⚠ 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

insert categories from a form please help



razerone

razerone
  • profile picture
  • Member

Posted 20 December 2013 - 09:14 AM

Hi I have a database table called categories.

 

But I would like to know how to make the controller and view work I am new to grocery crud please help. I would like to be able to insert categories form a form.

CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `parent_id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `date_added` datetime NOT NULL,
  `date_edit` datetime NOT NULL,
  `publish` int(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ;

preg

preg
  • profile picture
  • Member

Posted 09 January 2014 - 11:31 AM

hello razerone,

 

you have to add a function in your default controller (maybe home.php).

 

like this :

public function categories() {
        $crud = new grocery_CRUD();

        // CHOOSE YOUR TABLE SQL HERE
        $crud->set_table('categories');

        // CHOOSE YOUR SUBJECT HERE
        $crud->set_subject('Categorie');

        // CHOOSE YOUR PAGE TITLE HERE
        $this->template->set('title', 'Manage your Categories');
        
        // HERE WE WILL CREATE A RELATION FOR PARENT ID
        $crud->set_relation('parent_id','categories','name');
        // first param : foreign KEY
        // second param : table reference
        // third param : what column you want see in your list

        $output = $crud->render();

        // here call your template or layout to see your datas
        $this->template->load('your-layout',$output);
}

you don't have to do more. If you want change the type of data input see here :

http://www.grocerycrud.com/documentation/options_functions/field_type

 

I hope it wil be useful :)