ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

v 1.3.3 grocery CRUD - an automatic Codeigniter CRUD

April 11, 2011 3:24am

Subscribe [77]
  • #91 / Jun 17, 2011 10:52am

    WCDi

    4 posts

    I just started using grocery CRUD. It’s really helpfull! But now I’m stuck.
    I’m making a simple administration tool for products and some other stuff. I’m working on the product part for now. A product has a brand, a name, and possibly multiple EAN’s.

    I designed my database with a ‘product’-table and a ‘ean’-table. See the attached screenshot.
    What I would like now, is to be able to add multiple EAN’s while creating a new product. Is there a way to do this with grocery CRUD?

  • #92 / Jun 18, 2011 12:46pm

    fabgonber

    15 posts

    WCDI,

    Grocery Crud haves one limitation, the name of the primary key and the foreign key need be the same.

    looking two tables of your model: productsId is the pk of products, BUT in productsEans you need rename ProductEanProductId to ProductId.

    And next you can make the relation with grocery

  • #93 / Jun 19, 2011 7:46pm

    fabgonber

    15 posts

    I found a Grocery Crud Bug:

    If the method has the same name of the controller, the crud not render.

    class Listas extends CI_Controller {
    
        function __construct()
        {
            parent::__construct();
            
            /* Standard Libraries */
            $this->load->database();
            $this->load->helper('url');
            /* ------------------ */        
            $this->load->add_package_path(APPPATH.'third_party/grocery_crud/');
            $this->output->set_template('custom_cms');        
            $this->load->library('grocery_CRUD');    
        }
    
    
        function listas()
        {
                $crud = new grocery_CRUD();
                $crud->set_table('lista');
                $crud->set_relation('promotor_id','promotor','iniciales_promotor');
                $crud->render();
        }

    Regards
    Fabián

  • #94 / Jun 20, 2011 1:35am

    web-johnny

    235 posts

    I found a Grocery Crud Bug:

    If the method has the same name of the controller, the crud not render.

    class Listas extends CI_Controller {
    
        function __construct()
        {
            parent::__construct();
            
            /* Standard Libraries */
            $this->load->database();
            $this->load->helper('url');
            /* ------------------ */        
            $this->load->add_package_path(APPPATH.'third_party/grocery_crud/');
            $this->output->set_template('custom_cms');        
            $this->load->library('grocery_CRUD');    
        }
    
    
        function listas()
        {
                $crud = new grocery_CRUD();
                $crud->set_table('lista');
                $crud->set_relation('promotor_id','promotor','iniciales_promotor');
                $crud->render();
        }

    Regards
    Fabián

    Hmmmm yes, I think you’re right. I will have it in mind to change it . Thanks Fabián

  • #95 / Jun 20, 2011 9:17am

    WCDi

    4 posts

    WCDI,

    Grocery Crud haves one limitation, the name of the primary key and the foreign key need be the same.

    looking two tables of your model: productsId is the pk of products, BUT in productsEans you need rename ProductEanProductId to ProductId.

    And next you can make the relation with grocery

    Tnx for your reply. Unfortunately this is no solution to my problem because this does not allow me to select multiple EAN’s, but just one 😊 For now I changed my model a bit and will ask the user to enter the EAN’s comma-separated.

    I’ve got another question. Is there a way to pass some parameters to a callback function?  Also, if I use a callback for an edit field (callback_edit_field), is there a way to pre-fill file ‘value’-attribute with the corresponding value?

  • #96 / Jun 20, 2011 10:19am

    fabgonber

    15 posts

    Tnx for your reply. Unfortunately this is no solution to my problem because this does not allow me to select multiple EAN’s, but just one 😊 For now I changed my model a bit and will ask the user to enter the EAN’s comma-separated.

    WCDi, You need study relational models 😊

    what do you need to do:
    a) ¿One Ean has Many Products?
    b) ¿One Product Has Many Eans?
    c) ¿Many Eans has Many Products?

    Look: http://dl.dropbox.com/u/2891468/dibujo_modelo_relacional.png

  • #97 / Jun 20, 2011 11:07am

    WCDi

    4 posts

    WCDi, You need study relational models 😊

    what do you need to do:
    a) ¿One Ean has Many Products?
    b) ¿One Product Has Many Eans?
    c) ¿Many Eans has Many Products?

    Look: http://dl.dropbox.com/u/2891468/dibujo_modelo_relacional.png

    Option b. I’ve ‘studied’ relational models, but to be honest, it has been a while.. A product can have multiple EAN’s, and an EAN is unique to a product, so that’s option b. I would say that my model is right, or am I missing something?

    Thanks for your input and help!

  • #98 / Jun 20, 2011 11:47pm

    fabgonber

    15 posts

    If it’s “B” your model is right BUT you
    need ProductEanProductId to ProductId.

    ¿Are you trying select it from product crud? It’s easier do it
    from ean crud:


    <pre><code>
    function blah()
      {
    $crud = new grocery_CRUD();
    $crud->set_table('ean');
    $crud->set_relation('product_id','product','product_name');
    $crud->render();
    }
    <pre><code>

    You can make new eans with one product.

  • #99 / Jun 21, 2011 3:22am

    web-johnny

    235 posts

    WCDi I just created an example for the callback_edit_field in http://www.grocerycrud.com/crud/example/callback_edit_field. You can take two parameters 1- the value of the field and 2- the primary key value. You can view the example to see how it works (press an edit to see it).

    Also for the options of the callbacks you can see http://www.grocerycrud.com/crud/view/options_functions , I know it might be pure but is something compare to nada

  • #100 / Jun 21, 2011 11:01am

    dodulz

    4 posts

    I’M newbie use grocery CRUD ...
    it’s great plugin for CRUD, but I’Have problem with function set_model

    in my model I use this code

    <?php
    class MAsset extends grocery_Model {
    
        function __construct(){
            parent::__construct();
        }
        
        function getAll(){
                    $this->db->select('nama,email');
                    $this->db->from('newsletter');
                    $this->db->limit(10);
                    $this->db->order_by('id_newslatter','ASC');
                    $query = $this->db->get();
                    return $query->result();
        }
        
    
    }

    and in controller I use

    $this->load->library('grocery_Exceptions');
            try{
                /* This is only for the autocompletion */
                $crud = new grocery_CRUD();
    
                //$crud->set_theme('datatables');
                $this->load->model('MAsset');
                $datase = $this->MAsset->getAll();
                $crud->set_model($datase);
                $crud->set_subject('NewsLetter');
                $crud->required_fields('nama','email');
                $crud->columns('nama','email');
                $crud->render();
                
            }catch(Exception $e){
                $this->grocery_exceptions->show_error($e->getMessage(), $e->getTraceAsString());
            }

    Error in Output :

    Fatal error: Class 'grocery_Model' not found in C:\XXXX\XXX\application\models\MAsset.php on line 2

    How to Fix this problem ?

  • #101 / Jun 21, 2011 2:10pm

    WCDi

    4 posts

    If it’s “B” your model is right BUT you
    need ProductEanProductId to ProductId.

    ¿Are you trying select it from product crud? It’s easier do it
    from ean crud:

    function blah()
        {
                $crud = new grocery_CRUD();
                $crud->set_table('ean');
                $crud->set_relation('product_id','product','product_name');
                $crud->render();
        }

    You can make new eans with one product.

    Tnx for your reply 😊 I am indeed trying to (multiple) select/enter EAN’s from the product CRUD. This is more efficient for the end-user. But if this isn’t possible, I will have to do it the other way around, as you described 😊

    @web-johnny > Thank you for the example, that really helps 😊

  • #102 / Jun 21, 2011 5:00pm

    web-johnny

    235 posts

    I’M newbie use grocery CRUD ...
    it’s great plugin for CRUD, but I’Have problem with function set_model

    in my model I use this code

    <?php
    class MAsset extends grocery_Model {
    
        function __construct(){
            parent::__construct();
        }
        
        function getAll(){
                    $this->db->select('nama,email');
                    $this->db->from('newsletter');
                    $this->db->limit(10);
                    $this->db->order_by('id_newslatter','ASC');
                    $query = $this->db->get();
                    return $query->result();
        }
        
    
    }

    and in controller I use

    $this->load->library('grocery_Exceptions');
            try{
                /* This is only for the autocompletion */
                $crud = new grocery_CRUD();
    
                //$crud->set_theme('datatables');
                $this->load->model('MAsset');
                $datase = $this->MAsset->getAll();
                $crud->set_model($datase);
                $crud->set_subject('NewsLetter');
                $crud->required_fields('nama','email');
                $crud->columns('nama','email');
                $crud->render();
                
            }catch(Exception $e){
                $this->grocery_exceptions->show_error($e->getMessage(), $e->getTraceAsString());
            }

    Error in Output :

    Fatal error: Class 'grocery_Model' not found in C:\XXXX\XXX\application\models\MAsset.php on line 2

    How to Fix this problem ?

    For your CRUD that you say you don’t need any model. Forgot the models. The set_model is for more complicated projects. For your example you can do it like this:

    function my_newsletter(){
                $crud = new grocery_CRUD();
    
                $crud->order_by('id_newslatter','ASC');
                $crud->set_table('newsletter');
                $crud->set_subject('NewsLetter');
                $crud->required_fields('nama','email');
                $crud->columns('nama','email');
                $crud->render();
    }

    It’s an easy codeigniter CRUD , no need of models, views, javascripts. It’s easier than you think. Read the documentation and the installation for codeigniter 2 and see the working examples.

    Hope I help.

    Now if you want to use models in the future for your reasons - you will do it like this:

    $crud = new grocery_CRUD();
    
                $crud->set_theme('datatables');
                $crud->set_model('MAsset');
                $crud->set_subject('NewsLetter');
                $crud->required_fields('nama','email');
                $crud->columns('nama','email');
                $crud->render();

    and you MUST use your model by extending grocery_Model (That extends CI_Model) So if your model is something like this:

    class MAsset extends CI_Model {
    
        function __construct()
        {
            parent::__construct();
        }
    mpla mpla mpla….
    }

    Now it will be:

    class MAsset extends grocery_Model {
    //No need to have a contruct
    function getAll(){
    
    }
    mpla mpla mpla….
    }
  • #103 / Jun 21, 2011 11:51pm

    fabgonber

    15 posts

    Web-Jhony

    i’m having some problems with mysql stricted mode… the methods works fine in my laptop (ubuntu + mysql server + php5) but not in my server (debian + mysql + php5).

    In debian when i make a “add” i only see the “clock” rounding…. i can note the problem is because Grocery don’t make a insert with all the “campos”,

    example
    table person(id,dni,name,age) and i put $crud->fields(dni,name) grocery do insert into person(id,dni,name) values(x,y,z) but mysql fails because age is not defined in the insert stament.

    I feel is a problem in the mode of mysql… but i don’t know how i can change it.

  • #104 / Jun 22, 2011 4:04am

    web-johnny

    235 posts

    Web-Jhony

    i’m having some problems with mysql stricted mode… the methods works fine in my laptop (ubuntu + mysql server + php5) but not in my server (debian + mysql + php5).

    In debian when i make a “add” i only see the “clock” rounding…. i can note the problem is because Grocery don’t make a insert with all the “campos”,

    example
    table person(id,dni,name,age) and i put $crud->fields(dni,name) grocery do insert into person(id,dni,name) values(x,y,z) but mysql fails because age is not defined in the insert stament.

    I feel is a problem in the mode of mysql… but i don’t know how i can change it.

    This is probably a mysql problem as you said. But I still don’t know what. Can you do a php info and see : What Apache version do you use? What PHP version and what mysql?

  • #105 / Jun 22, 2011 3:03pm

    fabgonber

    15 posts

    This is probably a mysql problem as you said. But I still don’t know what. Can you do a php info and see : What Apache version do you use? What PHP version and what mysql?

    Debian http://dl.dropbox.com/u/2891468/phpinfo-debian.pdf (dont’t work)
    Ubuntu http://dl.dropbox.com/u/2891468/phpinfo-ubuntu.pdf (works!)

    when i do in phpmyadmin debian “insert into table(x,y,z) values(1,2,3)” and the table definition has (x,y,z,w) don’t work. BUT when i do the same in ubuntu the insert was
    done and w has a default value.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases