about row and input data
- Single Page
Posted 06 April 2012 - 09:51 AM
I'm newbie in Grocery Crud. And I need the fast information for my project.
This my some question:
[list=1]
[*]How to modify name row fieldname database. For example in database field name : 'nme' and in the view i want to use 'your name' ?
[*]How to make a dinamic value for id in input data Grocery. We can not input data id_ and system can make itself. For example in db record has 2000 and if i create data the id_ value was be automatic become 2001?
[*]To make a some value for input data. maybe : input country => english, arabia, australia, .... (not from database and just input in code)?
[/list]
Thank you for anyone want to help me.
Posted 06 April 2012 - 10:19 AM
1. use the display_as . You can see an example at: http://www.grocerycr...es/full_example
2. If you mean the auto-increment you don't need to. It's automatically added. Grocery CRUD auto-recognize the primary key and if it's auto-increment. So just make sure that you have your id as primary key and auto-increment and let the rest for grocery CRUD
3. You have to use callback_add_field ( http://www.grocerycr...d_field_example ) and callback_edit_field ( http://www.grocerycr...t_field_example ) and you can return a select. For example:
return "<select name='plan_id' id='' class='chosen-select' data-placeholder='Select Plan' style='width:300px'>
<option value=''></option><option value='1' >Plan 1</option><option value='2' >Plan 2</option>
</select>";
Please see all the examples that I have at the website and see what each example does.
Also if you need an API for each function you can go at: http://www.grocerycr...tions_functions
P.S I edited you title as this issue is not an urgent issue. It is just questions of how to use grocery CRUD.
Posted 06 April 2012 - 11:44 AM
Oh sorry for this. I don't know.
2. How do make CRUD auto increment?
3. Fail. this my code
$this->grocery_crud->callback_add_field('country',array($this,'add_field_callback_1'));
function add_field_callback_1()
{
return "<select name='country' id='' class='chosen-select' data-placeholder='Select Plan' style='width:300px'>
<option value=''></option><option value='eng' >England</option><option value='USA' >America</option>
<option value='Aus' >Australia</option>
</select>";
}
Posted 06 April 2012 - 12:17 PM
3. Can you post your function and the table?, probably you have something wrong at somewhere else.
When I say the table I mean only the structure for example:
CREATE TABLE IF NOT EXISTS `actor` (
`actor_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`fullname` varchar(250) NOT NULL,
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`actor_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=201 ;
Posted 06 April 2012 - 13:23 PM
3. This is my code and tabel
function country()
{
$crud = new grocery_CRUD();
$crud->set_theme('flexigrid');
$crud->set_table('country');
$crud->fields('id_country','country','mark_country');
$this->grocery_crud->callback_add_field('mark_country',array($this,'add_field_callback_1'));
$crud->required_fields('id_country','country','mark_country'); //mark_country=[eng||usa||aus]
$output = $crud->render();
$this->_example_output($output);
}
function add_field_callback_1()
{
return "<select name='country' id='' class='chosen-select' data-placeholder='Select Plan' style='width:300px'>
<option value=''></option><option value='ENG' >England</option><option value='USA' >America</option>
<option value='AUS' >Australia</option>
</select>";
}
id_country country mark_country
1 England ENG
2 America USA
3 Australia AUS
Thank you very much in advance forJohnny.
Posted 06 April 2012 - 13:35 PM
3. Is because you have:
//This is wrong
$this->grocery_crud->callback_add_field('mark_country',array($this,'add_field_callback_1'));
and not:
//This is correct
$crud->callback_add_field('mark_country',array($this,'add_field_callback_1'));
You have to choose everytime what object you will use. You can have $this->grocery_crud OR $crud not both in one function.
Posted 06 April 2012 - 14:05 PM
2. Hmm, i've a dateline project. Would you help me to do this.
[quote]Grocery CRUD doesn't support so complicated and unique customizations so you will have to change the core library of grocery CRUD to do this.[/quote]
Thank you Johnny.
Posted 06 April 2012 - 14:27 PM
The auto-increment is just a simple technic that you just add NULL to the id!! Nothing more!
Ok if you desperately want to do this for your reasons, you can do this without changing the core by simply using the callback_insert method.
I have an example of how to use the callback_before_insert at: http://www.grocerycr..._insert_example . It works with exactly same way but it just don't have any automated insert so use it rarely. The only difference is that you have to add your own logic there and return true or false. For example:
function example_callback_insert(){
$crud = new grocery_CRUD();
$crud->set_table('offices');
$crud->set_subject('Office');
$crud->required_fields('city');
$crud->columns('city','country','phone','addressLine1','postalCode');
$crud->callback_insert(array($this,'checking_post_code'));
$output = $crud->render();
$this->_example_output($output);
}
function checking_post_code($post_array)
{
/* Your own logic here */
if.... for($i ....)
$this->db->...
/* ------------------------- */
$post_array['country_id'] = $my_new_id;
$this->db->insert('my_table', $post_array);
return true;
}
Please try to do the logic by your own, as I prefer to answer more questions from other users to the forum than to try to solve every problem separately. I am sorry I just don't have enough time for this.
Posted 06 April 2012 - 14:45 PM
i'll get it ..
back of my question again:
when i use optional value when add or edit data. [i've write and use edit data for mark country] the field say [color=#444444][font=Arial, Helvetica, sans-serif][size=4]"mark_country field is required".[/size][/font][/color]
function edit_field_callback_1($value, $primary_key)
{
return "<select name='country' id='' class='chosen-select' data-placeholder='Select Plan' style='width:300px'>
<option value='".$value."'>".$value."</option><option value='ENG' >England</option><option value='USA' >America</option>
<option value='AUS' >Australia</option>
</select>";
}
function add_field_callback_1()
{
return "<select name='country' id='' class='chosen-select' data-placeholder='Select Plan' style='width:300px'>
<option value=''>"Mark of Country"</option><option value='ENG' >England</option><option value='USA' >America</option>
<option value='AUS' >Australia</option>
</select>";
}
what's wrong
Posted 07 April 2012 - 11:47 AM
$crud->required_fields('id_country','country','mark_country');
to
$crud->required_fields('id_country','country');
Posted 07 April 2012 - 13:11 PM
but in addition ; if i insert data that have required field. the field in database were be NULL value.. How solve this?
But i think i found a bug...
if i add data and after that has two choice: edit record and back to menu.
and if i choice 'edit record'
i found this:
[quote]
[b]Fatal error[/b][color=#000000]: Uncaught exception 'Exception' with message 'On the state "edit" the Primary key cannot be null' in /xampp/[/color][color=#000000]2251 Stack trace: #0 [/color]
[color=#000000]grocery_CRUD_States->getStateInfo() #1[/color]
[color=#000000]function]: Admin->dictionary('edit', '0') #3/xampp/[/color][color=#000000]system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #4[/color]
[color=#000000]xampp/[/color][b]application\libraries\grocery_crud.php[/b][color=#000000] on line [/color][b]2251[/b]
[/quote]
Posted 07 April 2012 - 15:31 PM
Thanks to remind it to me.
Posted 07 April 2012 - 19:22 PM
How for this:
if i insert data that have not required field. the field in database were be NULL value.. How solve this?
$crud->required_fields('id_country','country');
function edit_field_callback_1($value, $primary_key)
{
return "<select name='country' id='' class='chosen-select' data-placeholder='Select Plan' style='width:300px'>
<option value='".$value."'>".$value."</option><option value='ENG' >England</option><option value='USA' >America</option>
<option value='AUS' >Australia</option>
</select>";
}
function add_field_callback_1()
{
return "<select name='country' id='' class='chosen-select' data-placeholder='Select Plan' style='width:300px'>
<option value=''>"Mark of Country"</option><option value='ENG' >England</option><option value='USA' >America</option>
<option value='AUS' >Australia</option>
</select>";
}
I have insert mark_country but the result in database was NULL. Why?
Thank you
Posted 07 April 2012 - 19:29 PM
Posted 08 April 2012 - 09:12 AM
Thank you John.
See u again.
Posted 12 June 2012 - 22:04 PM
[quote]
[color=#4F5155]On the state "edit" the Primary key cannot be null --- #0 C:\wamp\www\definitions\src\application\libraries\grocery_crud.php(3324): grocery_CRUD_States->getStateInfo() #1 C:\wamp\www\definitions\src\application\controllers\examples.php(46): grocery_CRUD->render() #2 [internal function]: Examples->edit() #3 C:\wamp\www\definitions\src\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #4 C:\wamp\www\definitions\src\index.php(202): require_once('C:\wamp\www\def...') #5 {main}[/color]
[/quote]
This is the dump from MySQL:
[quote][font=courier new,courier,monospace]--[/font]
[font=courier new,courier,monospace]-- Table structure for table `definitions`[/font]
[font=courier new,courier,monospace]--[/font]
[font=courier new,courier,monospace]CREATE TABLE IF NOT EXISTS `definitions` ([/font]
[font=courier new,courier,monospace] `definition_id` int(11) unsigned NOT NULL AUTO_INCREMENT,[/font]
[font=courier new,courier,monospace] `term` varchar(64) NOT NULL,[/font]
[font=courier new,courier,monospace] `definition` text NOT NULL,[/font]
[font=courier new,courier,monospace] PRIMARY KEY (`definition_id`)[/font]
[font=courier new,courier,monospace]) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;[/font]
[font=courier new,courier,monospace]--[/font]
[font=courier new,courier,monospace]-- Dumping data for table `definitions`[/font]
[font=courier new,courier,monospace]--[/font]
[font=courier new,courier,monospace]INSERT INTO `definitions` (`definition_id`, `term`, `definition`) VALUES[/font]
[font=courier new,courier,monospace](1, 'start', 'stop');[/font][/quote]
Posted 12 June 2012 - 23:24 PM
Posted 28 August 2012 - 11:25 AM
3 This works:
function places_of_study()
{
$crud = new grocery_CRUD();
/**/
$crud->callback_column('status',array($this,'status_column'));
$crud->callback_field('status',array($this,'status_choice'));
/**/
}
public $status_choice = array("arh" => "arhive", "tst" => "test", "loc" => "local");
function status_choice($value, $pk)
{
$_status_field = $this->status_choice;
$str = "<select name='status' id='' class='chosen-select' data-placeholder='Select status' style='width:300px'>";
if(isset($_status_field[$value])) {
$str = $str."<option value='$value' select>$_status_field[$value]</option>";
} else {
$str = $str."<option value='$value' select>$value</option>";
}
foreach( $_status_field as $key => $val){
if ($key != $value) {
$str = $str."<option value='$key'>$val</option>";
} else {
continue;
}
}
$str = $str."</select>";
return $str;
}
function status_column($value, $arr)
{
$_status_arr = $this->status_choice;
if (isset($_status_arr["$value"])) {
return $_status_arr["$value"];
}
return $value;
}
Posted 30 August 2012 - 11:57 AM