Create an alias of a column
Posted 24 June 2012 - 11:01 AM
Posted 24 June 2012 - 11:13 AM
For now a workaround for this till will be fixed is to have only the one of the two columns there or ... if it is possible to rename the one of the two fields. So you can use display_as to change it and add your names there.
Kindest Regards
Johnny
Posted 24 June 2012 - 11:27 AM
Best regards,
Arefin
Posted 24 June 2012 - 11:38 AM
[b]subjects[/b]
- subject_id (this is ok)
- subject_name
- subject_description
- subject_date
....
it is better to have
[b]subjects[/b]
- subject_id
- name
- description
- inserted_date
...
So it is not a design mistake for me it's just OK.
I also added as a bug to track it and it will probably be fixed as for the next version ( https://github.com/s...-crud/issues/68 )
Posted 24 June 2012 - 12:24 PM
Posted 24 June 2012 - 12:32 PM
Thanks to share your thoughts and thanks to mention the bug
Posted 24 June 2012 - 12:51 PM
Posted 24 June 2012 - 13:45 PM
public function view() {
$data = array();
if (!($this->ion_auth->logged_in() && $this->ion_auth->is_admin())) {
$data['login'] = TRUE;
$data['logout'] = FALSE;
$data['label'] = 'Signin';
redirect($this->config->item('base_url') . 'auth', 'refresh');
} else {
$data['login'] = FALSE;
$data['logout'] = TRUE;
$data['label'] = 'Signout';
}
$this->grocery_crud->set_theme('datatables');
$this->grocery_crud->set_table('subcategories');
//Set relation
$this->grocery_crud->display_as('category_id','Category Name');
$this->grocery_crud->set_subject('Subcategory');
$this->grocery_crud->set_relation('category_id','categories','name');
//Set relation
//Validation
$this->grocery_crud->required_fields('name','description');
$output = $this->grocery_crud->render();
$this->load->view('header');
$this->load->view('site_start');
$this->load->view('admin/menu', $data);
$this->load->view('admin/category/subcategory/view', $output);
$this->load->view('admin/footer');
}
Attached the images of db and the output
[img]http://bangladeshsurvey.com/public/images/for_johnny/cat&subcat.JPG[/img]
[img]http://bangladeshsurvey.com/public/images/for_johnny/db.JPG[/img]
cheers
Posted 24 June 2012 - 14:18 PM
//As for PHP version >= 5.3
$this->grocery_crud->callback_column('name',function($value,$row){
return $row->name;
});
or as for PHP version < 5.3
//As for PHP version < 5.3
$this->grocery_crud->callback_column('name',array($this,'custom_callback_column'));
and
public function custom_callback_column($value,$row){
return $row->name;
}
at your main controller
Posted 24 June 2012 - 16:31 PM
Posted 24 June 2012 - 18:27 PM
public function view() {
$data = array();
if (!($this->ion_auth->logged_in() && $this->ion_auth->is_admin())) {
$data['login'] = TRUE;
$data['logout'] = FALSE;
$data['label'] = 'Signin';
redirect($this->config->item('base_url') . 'auth', 'refresh');
} else {
$data['login'] = FALSE;
$data['logout'] = TRUE;
$data['label'] = 'Signout';
}
$this->grocery_crud->set_theme('datatables');
$this->grocery_crud->set_table('subcategories');
//Set relation
$this->grocery_crud->display_as('category_id','Category Name');
$this->grocery_crud->set_subject('Subcategory');
$this->grocery_crud->set_relation('category_id','categories','name');
$this->grocery_crud->callback_column('name',array($this,'custom_callback_column'));
//Set relation
//Validation
$this->grocery_crud->required_fields('name','description');
$output = $this->grocery_crud->render();
$this->load->view('header');
$this->load->view('site_start');
$this->load->view('admin/menu', $data);
$this->load->view('admin/category/subcategory/view', $output);
$this->load->view('admin/footer');
}
public function custom_callback_column($value,$row){
return $row->name;
}
For more about how to use the callback_column you can see and example at: http://www.grocerycr..._column_example and http://www.grocerycrud.com/documentation/options_functions/callback_column
Posted 25 June 2012 - 03:15 AM
Posted 25 June 2012 - 06:25 AM
CREATE TABLE IF NOT EXISTS `employees` (
`employeeNumber` int(11) NOT NULL AUTO_INCREMENT,
`lastName` varchar(50) NOT NULL,
`firstName` varchar(50) NOT NULL,
`extension` varchar(10) NOT NULL,
`email` varchar(100) NOT NULL,
`officeCode` varchar(10) NOT NULL,
`file_url` varchar(250) CHARACTER SET utf8 NOT NULL,
`jobTitle` varchar(50) NOT NULL,
PRIMARY KEY (`employeeNumber`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1703 ;
also can you please tell me what codeigniter version do you use and what grocery CRUD version?
Sorry but I still don't understand where the problem can be as I didn't have a same bug before
Posted 25 June 2012 - 08:50 AM
Subcategory:
DROP TABLE IF EXISTS `subcategories`;
CREATE TABLE `subcategories` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`description` varchar(255) NOT NULL,
`category_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_category` (`category_id`),
CONSTRAINT `fk_category` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
Category:
DROP TABLE IF EXISTS `categories`;
CREATE TABLE `categories` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`description` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `cat_name` (`name`) USING BTREE,
KEY `cat_desc` (`description`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;
Posted 25 June 2012 - 22:02 PM
Posted 26 June 2012 - 04:54 AM
Posted 26 June 2012 - 06:24 AM
[attachment=210:Untitled-1.png]
So perhaps it is a key problem that grocery CRUD haven't recognized the primary key but not sure as it is a really strange bug. A solution for this is to update the grocery CRUD to the latest version 1.2.3 (you will not have any problem with the update probably), just make sure that you copy all the files (included the assets folder) and not only the library and the model. After upgrading it you can have this simple line of code:
$crud->set_primary_key('id');
Hopefully this will solve the problem. But still I don't know what else to see. There is something with your local machine. So you have to install the grocery CRUD from scratch just to check that this is working for you and then debug it and see what is wrong with the template e.t.c. It is not the best solution but I really don't know what could cause this problem to you.
Posted 26 June 2012 - 06:33 AM
$crud->set_primary_key('id');
But no result. One thing I am not sure about is that when I use
$this->grocery_crud->callback_column('name', array($this, 'custom_callback_column'));
how this should work bcoz both of the column name is 'name'. I am confused here.
Posted 26 June 2012 - 06:43 AM
Posted 26 June 2012 - 07:14 AM
public function my_view() {
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('subcategories');
//Set relation
$crud->display_as('category_id','Category Name');
$crud->set_subject('Subcategory');
$crud->set_relation('category_id','categories','name');
//Set relation
//Validation
//$crud->callback_column('name',array($this,'custom_callback_column'));
$crud->required_fields('name','description');
$output = $crud->render();
$this->_example_output($output);
}
But still I have not luck to find where the problem can be