⚠ In case you've missed it we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This forum is read-only and soon will be archived. ⚠


Member Since 11 Nov 2011
Offline Last Active Jan 28 2014 08:33 AM

Topics I've Started

GroceryCRUD multigrid and set_model [SOLVED]

18 June 2013 - 08:36 AM

Seems that we cannot use set_model in multigrid without having relation_n_n array mixed up.

I've successfully manage this with several error messages.


The error messages show that there is a problem with unloading a model with unset.
Do anybody know how to unload the model correctly?

        public function new_crud(){
            $db_driver = $this->db->platform();
            $model_name = 'grocery_crud_model_'.$db_driver;
            $crud = new Grocery_CRUD();
            if (file_exists(APPPATH.'/models/'.$model_name.'.php')){
            return $crud;

	function multigrids()

		$output1 = $this->offices_management2();

		$output2 = $this->employees_management2();

		$output3 = $this->customers_management2();

		$js_files = $output1->js_files + $output2->js_files + $output3->js_files;
		$css_files = $output1->css_files + $output2->css_files + $output3->css_files;
		$output = "<h1>List 1</h1>".$output1->output."<h1>List 2</h1>".$output2->output."<h1>List 3</h1>".$output3->output;

				'js_files' => $js_files,
				'css_files' => $css_files,
				'output'	=> $output

	public function offices_management2()
		$crud = $this->new_crud();


		$output = $crud->render();

		if($crud->getState() != 'list') {
		} else {
			return $output;

	public function employees_management2()
		$crud = $this->new_crud();

        $crud->display_as('officeCode','Office City');




		$output = $crud->render();

		if($crud->getState() != 'list') {
		} else {
			return $output;

	public function customers_management2()

		$crud = $this->new_crud();

        $crud->display_as('salesRepEmployeeNumber','from Employeer')
             ->display_as('contactLastName','Last Name');


		$output = $crud->render();

		if($crud->getState() != 'list') {
		} else {
			return $output;

GroceryCRUD with Various Database Support.

15 June 2013 - 12:03 AM

Hi everyone.
I plan to add PDO support to groceryCRUD.

In order to do that, I need to change any MySQL specific query into the more generic one.

Below is some MySQL specific query that exists on /application/models/grocery_crud_model.php:

  • CONCAT  <-- work around: use PHP instead of query
  • COALESCE <-- work around: use PHP instead of query
  • GROUP_CONCAT <-- work around: use PHP instead of query
  • SHOW COLUMNS FROM table_name <-- work around: do "SELECT * FROM table_name", get the key array. But this will only work if the table is not empty. OR even better $this->db->list_field (http://ellislab.com/...ase/fields.html)


If any of you find some specific MySQL specific query, please post it here.
And if you have a better workaround, please also post it here.

It is gonna be cool if groceryCRUD can support PDO, but it gonna be cooler if we can also contribute to this "big leap".


If you want to use PDO, try to change /application/config/database.php into something like this:

$db['default']['hostname'] = 'mysql:host=localhost;port=3306;dbname=module_devel';
$db['default']['username'] = 'root';
$db['default']['password'] = 'toor';
$db['default']['database'] = 'module_devel';
$db['default']['dbdriver'] = 'pdo';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

UPDATE: here is the fork https://github.com/g...rd/grocery-crud

I've also make a pull request https://github.com/s...y-crud/pull/191


It is working with CodeIgniter 3.0 and sqlite.

The changes are:

  • Rename /application/libraries/grocery_crud.php into /application/libraries/Grocery_CRUD.php
  • Rename grocery_crud class into Grocery_CRUD
  • Change
     $this->db->query("SHOW COLUMNS FROM `{$this->table_name}`")



    and adjust the script below that. However, there is not "NULL" information when we use $this->db->field_data

  • Remove $this->db->limit(1) in db_delete function in the model, since it will produce error in sqlite.

  • Change  

    return $this->db->field_exists($field,$table_name);


    $field_data_list = $this->db->field_data($table_name);
    foreach($field_data_list as $field_data){
        if($field_data->name == $field) return TRUE;
    return FALSE;

    Probably CodeIgniter guys doesn't complete $this->db->field_exists for pdo sqlite yet. However using $this->db->field_data() to emulate $this->db->field_exists is possible




Today I try to play with postgre SQL with no luck. Below are the problems:

  • postgre (and other standard SQL) use double quote ("), while mysql & sqlite use backtick (`). Does anyone know how to force CodeIgniter db driver to show escape character?
  • postgre doesn't provide primary key information. So, user must explicitly do $crud->set_primary_key() for all the tables, otherwise the model will assume first field as primary key.




web-johnny has make a new repository (https://github.com/s...-crud-databases). The repository contains some model skeletons. With this approach, I don't need to fully mess around with "generic SQL". So I fork the repository and here it is: https://github.com/g...-crud-databases

  • I add an "examples" controller. This controller will automatically detect your db-driver and choose appropriate model for you.
  • I also add "grocery_crud_generic_model". I change backtick (`) into $this->db->protect_identifier(). Of course it cannot handle everything, but at least it should help.
  • This is incomplete yet, so that I don't make a pull request yet.



I've make some progress on PDO library. All "select" work for MySQL & sqlite. Postgre's primary key can be detected automatically.




The first pull request has been made: https://github.com/s...atabases/pull/1

  • The select mode of all examples is fully working,
  • The edit, insert, and delete operation is not tested yet.
  • The test has been performed by using sqlite, mysql, and postgresql. PDO driver used for all of the case


https://github.com/s...-crud-databases is ready.... Now you can use groceryCRUD with PDO driver for MySQL, Sqlite & Postgree. However it is not fully tested yet. Please report if something doesn't work as it should.



Right now, enum & set field doesn't work on postgree. So, you might consider to use relation_n_n & relation instead



Today I try to use GC 1.4 and CI 3.0 in No-CMS development branch. Some bugs occurred, especially when I try to use a table with a relation to itself. I've finally able to manage this and put another pull request https://github.com/s...atabases/pull/3

No-CMS Forum

17 May 2013 - 08:47 AM

First I want to clarify this:
No-CMS = CodeIgniter + groceryCRUD + some other components + my codes.
So, the problem you have when using No-CMS is sometimes not even related to groceryCRUD, nor it is related to CodeIgniter. Therefore, post your No-CMS specific problem here will sometime make some confusion.

If you think that your problem is groceryCRUD issue, please post it in this forum.
But, if you think that your problem is specific to No-CMS (e.g: user authentication, navigation management, making new widget, themes and modules), it'll be better that you post your problem in No-CMS forum here: http://www.getnocms.com/forum/


Thanks :)



No-CMS tutorial

07 May 2013 - 04:03 AM

Long time not visit this forum. I was (and am still) busy with my thesis.
I've write some tutorial about No-CMS, so that people can get idea about how to use it.
Please visit https://github.com/g...diAsgard/No-CMS

Some new features and bug-fix has been added.
Also, I've get my another paypal activated, so people can support by send little donation ;)

CodeIgniter autocompletion trick

16 February 2013 - 12:52 AM

The most terrible thing when develop CodeIgniter based application is netbeans/eclipse missing auto-completion feature. For example, when you load a model, netbeans/eclipse cannot automatically show you what functions available in that model.

There is a "trick" for that:

$this->your_model = new Your_Model(); 


By adding that line, now you can have a working auto-completion to make your development time more painless :)

However it has some consideration:

  1. You will need to add an extra line for that
  2. The model will be instantiated twice

‚ÄčThis trick also works for "library". And groceryCRUD example already use such a trick.