⚠ 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 is an archived forum. ⚠

  •     

profile picture

GroceryCRUD multigrid and set_model [SOLVED]



goFrendiAsgard
  • profile picture
  • Member

Posted 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;
            unset($this->{$model_name});
            $this->load->library('grocery_CRUD');
            $crud = new Grocery_CRUD();
            if (file_exists(APPPATH.'/models/'.$model_name.'.php')){
                $this->load->model('grocery_crud_model');
                $this->load->model('grocery_crud_generic_model');
                $crud->set_model($model_name);
            }
            return $crud;
        }

	function multigrids()
	{
		$this->config->load('grocery_crud');
		$this->config->set_item('grocery_crud_dialog_forms',true);
		$this->config->set_item('grocery_crud_default_per_page',10);

		$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;

		$this->_example_output((object)array(
				'js_files' => $js_files,
				'css_files' => $css_files,
				'output'	=> $output
		));
	}

	public function offices_management2()
	{
		$crud = $this->new_crud();
		$crud->set_table('offices');
		$crud->set_subject('Office');

		$crud->set_crud_url_path(site_url(strtolower(__CLASS__."/".__FUNCTION__)),site_url(strtolower(__CLASS__."/multigrids")));

		$output = $crud->render();

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

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

        $crud->set_theme('datatables');
        $crud->set_table('employees');
        $crud->set_relation('officeCode','offices','city');
        $crud->display_as('officeCode','Office City');
        $crud->set_subject('Employee');

        $crud->required_fields('lastName');

        $crud->set_field_upload('file_url','assets/uploads/files');

		$crud->set_crud_url_path(site_url(strtolower(__CLASS__."/".__FUNCTION__)),site_url(strtolower(__CLASS__."/multigrids")));

		$output = $crud->render();

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

	public function customers_management2()
	{

		$crud = $this->new_crud();

		$crud->set_table('customers');
        $crud->columns('customerName','contactLastName','phone','city','country','salesRepEmployeeNumber','creditLimit');
        $crud->display_as('salesRepEmployeeNumber','from Employeer')
             ->display_as('customerName','Name')
             ->display_as('contactLastName','Last Name');
        $crud->set_subject('Customer');
        $crud->set_relation('salesRepEmployeeNumber','employees','lastName');

		$crud->set_crud_url_path(site_url(strtolower(__CLASS__."/".__FUNCTION__)),site_url(strtolower(__CLASS__."/multigrids")));

		$output = $crud->render();

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

goFrendiAsgard
  • profile picture
  • Member

Posted 18 June 2013 - 09:20 AM

Solved.

Since [member="web-johnny"] has provide basic_model property as public, I'm able to do a bit hack :)

 

public function new_crud(){
        $db_driver = $this->db->platform();
        $model_name = 'grocery_crud_model_'.$db_driver;
        $model_alias = 'm'.substr(md5(rand()), 0, rand(4,15) );

        unset($this->{$model_name});
        $this->load->library('grocery_CRUD');
        $crud = new Grocery_CRUD();
        if (file_exists(APPPATH.'/models/'.$model_name.'.php')){
            $this->load->model('grocery_crud_model');
            $this->load->model('grocery_crud_generic_model');
            $this->load->model($model_name,$model_alias);
            $crud->basic_model = $this->{$model_alias};
        }
        return $crud;
    }

davidoster
  • profile picture
  • Member

Posted 20 June 2013 - 14:31 PM

For all the people that use this forum

This is only true for unstable development version 1.4


goFrendiAsgard
  • profile picture
  • Member

Posted 20 June 2013 - 22:39 PM

[member="davidoster"]: Hi, which one is only true for 1.4?
The problem, the solution, or both?

 

UPDATE:

Okay, [member="davidoster"] is right. The problem laid on CodeIgniter. CodeIgniter 2.1.3 doesn't have PDO subdriver, while CodeIgniter 3.0 have. I'll try to find more "generic" solution. Thanks


davidoster
  • profile picture
  • Member

Posted 20 June 2013 - 23:28 PM

Not only on CI 3.0 [member=gofrendiasgasrd].

You mention about multigrids. Multigrids exist only on the development version 1.4!!!


goFrendiAsgard
  • profile picture
  • Member

Posted 21 June 2013 - 11:02 AM

Oh, my bad. Really sorry  :unsure:


davidoster
  • profile picture
  • Member

Posted 21 June 2013 - 23:45 PM

It's ok! No worries!