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]
  • #286 / Mar 04, 2012 9:40am

    Pieter

    34 posts

    Hi web-johnny,

    I’ve just worked on a simple users table and ran into an issue with the is_unique validation.
    Osci wrote a nice My_Form_validation to solve the is_unique problem when editing: http://ellislab.com/forums/viewthread/192334/

    Part of the controller:

    $state = $this->grocery_crud->getState();
    $state_info = $this->grocery_crud->getStateInfo();
    
    if( $state == 'insert_validation' )
    {
     $this->grocery_crud->set_rules('password', 'Password', 'trim|required');
     $this->grocery_crud->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[clients.email]');
    }
    
    if( $state == 'update_validation' )
    {
     $this->grocery_crud->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[clients.email.id.'.$state_info->primary_key.']');
    }

    Now I had to change two things in the grocery_CRUD library to make this happen.
    1) Change the getStatInfo() to return a primary_key as it was emtpy on “update_validation”.
    2) Change the is_unique method into that of the one Osci wrote.

    Question: Is there a better way to handle unique fields? And is there a way to extend the grocery_CRUD library?

     

     

  • #287 / Mar 06, 2012 4:35pm

    iozivel

    1 posts

    Hi,
    I’m having some problems using Grocery CRUD in my website. I’ve found out that the problem is actually the URI language identifier library (http://codeigniter.com/wiki/URI_Language_Identifier).

    Grocery crud is working, so if I load the examples in the library, at this address: http://localhost/website/examples/offices_management, I can see the table with all the rows, I can sort them and so on. The problem is when I try to add/edit. Indeed, the add button, for example, points here: http://localhost/website/offices_management/add. It gives me an error since the url is missing the “examples” part, that is the controller name.

    If I delete the URI language identifier controller it works, but I need it. The problem, I think, is that is doing stuff with the url.

    Does anyone know how to solve this?


    In the library file ‘grocery_crud.php’ replace all ‘$ci->uri->segments’ with ‘$ci->uri->rsegments’.

  • #288 / Mar 07, 2012 10:22pm

    mayfield

    1 posts

    Hi,
    I’m having some problems using Grocery CRUD with my database…
    Here my table design.
    Orders :
    id, products_id,qty,discount, total,etc…
    Products:
    products_id,unit_price, discounted(bool), etc…

    The rule is, if products is discounted, in add or edit orders we can set the discount value(based on orders qty) else field is hidden, and total field is hidden in add or edit but the value will be (unit_price - discount).

    i just can’t figure out how to get and set those field values using Grocery CRUD.

    can someone help me please.

  • #289 / Mar 12, 2012 1:16pm

    bluehat09

    6 posts

    —edit—
    Just for dumb a$$ as me: in database config file change active records to TRUE!
    It works just fine. 

    @web-johhny: Sorry to bother with this basic question but I can’t make it work.
    Maybe is something in my configuration, maybe not.

    So I tried your basic example but I got all the time:
    Fatal error: Call to undefined method CI_DB_mysql_driver::select() in C:\xampp\htdocs\...\application\models\grocery_model.php on line 41

    I’m sure all files are in place: library, model, assets etc.

    Can you help, please?

    Many thanks,
    Adrian

  • #290 / Mar 12, 2012 7:19pm

    web-johnny

    235 posts

    Hi,
    I’m having some problems using Grocery CRUD with my database…
    Here my table design.
    Orders :
    id, products_id,qty,discount, total,etc…
    Products:
    products_id,unit_price, discounted(bool), etc…

    The rule is, if products is discounted, in add or edit orders we can set the discount value(based on orders qty) else field is hidden, and total field is hidden in add or edit but the value will be (unit_price - discount).

    i just can’t figure out how to get and set those field values using Grocery CRUD.

    can someone help me please.

    @mayfield you have double post this question. And you couldn’t even wait one day for the answer…!

     

  • #291 / Mar 13, 2012 7:13am

    bluehat09

    6 posts

    —edit—

    Discover add_action()

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

    No answer need it. Thanks.

    Hi,

    There is a way to use gCRUD to make custom actions on table view? E.g: Add near delete, edit a custom action “complete order”.

    I meant move records from one table to another. Let’s say I have one order in orders table and I want to move one record by its id to closed_orders table.

    Thank you.

  • #292 / Mar 15, 2012 3:47am

    web-johnny

    235 posts

    —edit—

    Discover add_action()

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

    No answer need it. Thanks.

    Hi,

    There is a way to use gCRUD to make custom actions on table view? E.g: Add near delete, edit a custom action “complete order”.

    I meant move records from one table to another. Let’s say I have one order in orders table and I want to move one record by its id to closed_orders table.

    Thank you.

    You can use the callback_column for that and add it like a link or a button. There are two parameters there ($value, $row). You can take for example the $row->id and have queries there or an information for another table e.t.c.

  • #293 / Mar 16, 2012 4:18pm

    Matalina

    191 posts

    I see in the documentation that you can’t turn crsf on.  Why can’t you?  What problems does it tell you?  Just the typical You can’t do that action?

    You know that’s relatively easy to fix.

    I have crsf on my site turned on, forgot that grocery crud didn’t like it.  and I went looking into the views.  The reason I got the error I got was because the crsf token was being created.  Easy fix:

    <?php
        preg_match('/^http:\/\/\w*\.*\w+\.\w+\/.*\/*index\.php*(.+)/',$update_url,$matches);
        $update_url = $matches[1];
        echo form_open_multipart($update_url, "method='post' id='crudForm' autocomplete='off'");
      ?>

    instead of

    <form action='<?php echo $update_url?>' method='post' id='crudForm' autocomplete='off' enctype="multipart/form-data">

    Now if this causes something else to go wacko then that may not help, but the error I got was easy to fix.  I’m having other issues but I think it’s a theme issue when I moved from my test site to my internal intrant net application with sign on templates and a lot of other things going on.

    ***

    nevermind.  It was only working because my code was doing something else. and messing up gc’s code.

  • #294 / Mar 16, 2012 7:42pm

    web-johnny

    235 posts

    Actually I saw that in every ajax post I have to add another post field that is required to “authorize” the crsf. I just don’t have so much time to look at it and I forgot it. A quick fix if you want to have both to your project (Grocery CRUD and crsf) is:

    go to application/config/config.php and add :

    list($tmp, $first_segment)  = explode("/",$_SERVER['PATH_INFO']);
    $config['csrf_protection'] = $first_segment == 'admin' ? false : true;

    This actually inactivates the csrf_protection only to “admin” controller. You can of course change this idea to your needs. If you have a good authorization library I don’t think you will have a problem with this. The most common problems for the csrf_protection is to frontend website . Some auto bots, hacks e.t.c.

     

  • #295 / Mar 19, 2012 9:18am

    Matalina

    191 posts

    Thanks.  I’ll do that.

  • #296 / Mar 23, 2012 9:35am

    KaBaDaBrA

    22 posts

    If you are looking to use dependent dropdown boxes - have a look at
    Categories and Sub-categories

    Once again awesome work web-johnny - loving GCRUD!!!!! :cheese:

  • #297 / Mar 27, 2012 1:37pm

    yepwingtim

    3 posts

    Hi Web-johnny,

    Is it possible dynamically add form elements in a single form?

    such as this.

    http://www.randomsnippets.com/2008/02/21/how-to-dynamically-add-form-elements-via-javascript/

    I need this so when a client comes in I can go to “edit” mode and add another “date” that they came in.

    thanks

  • #298 / Mar 27, 2012 3:03pm

    web-johnny

    235 posts

    No till this version. I am sorry. I have it though in my long-term plans.

  • #299 / Mar 28, 2012 2:17am

    goFrendiAsgard

    125 posts

    Hi Web-johnny,

    Is it possible dynamically add form elements in a single form?

    such as this.

    http://www.randomsnippets.com/2008/02/21/how-to-dynamically-add-form-elements-via-javascript/

    I need this so when a client comes in I can go to “edit” mode and add another “date” that they came in.

    thanks

    I think this is another “view” of “master-detail” form (and it is not easy developing that). As long as I know some people still works in master-detail feature. Maybe “additional-input” will be added later after “master-detail” function completed

  • #300 / Apr 12, 2012 11:03am

    Matalina

    191 posts

    How can I unset the jquery file in grocery crud.  I want to use the latest as it has the on function.  I don’t want to have to rewrite my code for on set of pages.

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

ExpressionEngine News!

#eecms, #events, #releases