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.

Customizable CRUD

February 16, 2008 12:03pm

Subscribe [15]
  • #16 / Feb 23, 2008 10:06am

    gyo

    170 posts

    adamp1 + xwero: yeah guys I agree with you, actually the original CRUD library comes with absolutely NO layout informations (infact without a css provided in the example the form will show up in a default way, ready to be styled).


    atasa: I’ll try your code and think about a table-mapping feature! Although I’m still oriented to an automated dynamic.

    EDIT: Only the “Read” method which displays tabular data comes with a table layout, but I’d like to allow its style customization too.

    Btw I still can’t get to release a 0.2 version cause I’d like to implement some stuff and didn’t have the time to get it working as I wish!

  • #17 / Feb 24, 2008 10:21am

    gyo

    170 posts

    Hello!

    I published CRUD 0.2, the downloads are in the first post of the thread, thankss!

  • #18 / Feb 24, 2008 10:49am

    Atasa

    29 posts

    OK suashi I will have a look at your progress…

    For adamp1 + xwero
    As you know we don’t deal with views yet.
    OK we can display the form in a division instead of a table.
    I am also in favor of tabless layouts but actually wanted to try the table class in this case.
    I will correct that soon.
    You may also want to provide ccs and template views for the different views we gonna use if you like

    Cheers

  • #19 / Feb 24, 2008 11:08am

    gyo

    170 posts

    I’m sorry I did I mistake with fields, please download it again, thanks!

  • #20 / Feb 24, 2008 2:17pm

    PedroGrilo

    18 posts

    suashi, thanks for your work on this.

    I’m really in-love with the simplicity of your lib.

    Keep it up!

  • #21 / Feb 24, 2008 2:58pm

    gyo

    170 posts

    PedroGrilo I’m glad you say it so! It is my first target to keep everything SIMPLE!
    And btw any suggestion is always welcome 😉


    I’d like to give info about my TODO list… so I’m working on:

    - fields validation so you can add your own rules
    - implementing a way to call a function before and/or after the database query
    - implement relational functions to allow more advanced structure of data


    cheers!
    gyo

  • #22 / Feb 25, 2008 6:32am

    Atasa

    29 posts

    Chao gyo,
    by tomorrow the leatest i will post the datagrid component.
    But I have to say one thing more.
    I don’t agree about creating the information for the forms in the php files.
    You can create another table in the database with this information like (Data mapping schema information).
    In this way it is easier to change setting for your project.

    Cheers

  • #23 / Feb 25, 2008 10:31am

    kucerar

    42 posts

    Hi kucerar!

    ATK is quite advanced and has a very complex structure, and I already found some inspiration… thanks!

    Good for you…

    Take a look at some of the other Ignited Code threads,  a lot of people are finding the same damn problem and reaching for the same damn solution 😉  that ATK has already done.  It’s been there it’s done that,  and it’s got the t-shirt…  There’s an offshoot Rails project called Streamlined that has realized the same CRUD thing,  Rails is template-driven and we’re all tired of that.  This is the same problem I faced 8 years ago with plain old JSPs trying to tie 70 odd questionnaire fields to a table without doing too much work.

    ATK URLs look nasty however…it was programmed before the trend to friendly URLs.  Have to fix that.  It’s also slow.  You’ll need eaccelerator to run it due to all the classloading. There’s a lot of stuff going on in there,  makes me nervous sometimes,  but not as nervous as zend framework for some reason.

    -R

    UPDATE:

    Good grief… they have quite a dbforge over there.  They generate the tables from the node specification.. check out the Achievo package,  in directory modules/setup,  there’s a setup node that shows example of using their DDL class.  I had expected to find examples of using DDL class,  and generic field types, which I need to dynamically build tables and be cross-db,  but had not expected to find that they define the actual tables in the node,  and use those for the source definitions.

  • #24 / Feb 25, 2008 3:50pm

    timj

    80 posts

    I like what I’m seeing so far, however, I am getting the following error in my view file, once for every record in my table:

    Undefined property: Crud::$options
    Filename: libraries/Crud.php
    Line Number: 115

    As far is I can tell, $options is a conditional (custom options) and I don’t see this referenced in your User Guide.  I’ve not assigned any custom options, why am I getting this error?

  • #25 / Feb 25, 2008 4:02pm

    gyo

    170 posts

    atasa: I agree that the fields should not be declared in the controller, I was thinking about placing the forms definitions in a model file; in the next release I’ll provide an example that uses models. Btw I’ll wait for your data grid 😉

    Edit: I forgot to say that the library will support a pre-defined schema as well; you can customize it to automatically parse the db fields, or grabbing configuration from a table.


    kucerar: then I’ll give a deeper look! :D

    ...gyo

  • #26 / Feb 26, 2008 2:17pm

    Atasa

    29 posts

    Chao gyo
    You will have to give some time more ‘couse i had a back pain attack, while carrying wood for the fire place.
    See you again tomorrow.


    Cheers

  • #27 / Feb 26, 2008 3:48pm

    Majd Taby

    637 posts

    Guys, take a look at CodeExtinguishers’ CodexForms library. It’s a very flexible and extendible form generator.

  • #28 / Feb 28, 2008 7:27pm

    gyo

    170 posts

    Atasa: take care! 😉


    jTaby: I was using your powerful library and I fall in love with it for its versatility, if I’m writing CRUD library is to create an automated system that I can fully understand. Big respect for CodeExtinguisher and Rapyd which are great and advanced tools.


    byee

  • #29 / Feb 29, 2008 6:03am

    Atasa

    29 posts

    OK gyo,
    I just manage to stand up a bit it was a very painful situation…
    But I came with the first attempt for the datagrid while in bed.
    You can just bind a multidimensional array.
    The array includes:
    a. info for the table like Caption and for the pagination.
    b. info for the table header
    c. info for the the tablebody
    d. i have included a basic template on the fly.

    Returns a well formed html table and pagination links

    What i will like to see more now is how to add dynamically edit + delete buttons.
    For me the ideal will be to pass a JavaScript callback function to the buttons
    for more user interaction.

    But thats the next step.

    Cheers

    <?php
    
    class Datagrid extends Controller {
    
    
        function Datagrid()
        {
            parent::Controller();
            $this->load->library('table');
            $this->load->helper('url');
            $this->load->library('pagination');
        }
    
        function index()
        {
        $tableheader = array();
        $tablebody = array();
        $paging = array();
    
        $tableData = array(
            'tblinfo' => array(
                'CAPTION' => 'This is My Datagrid',
                'ID_NAME' => 'FIELD_ID',
                'PER_PAGE' => 20,
                'TOTAL_ROWS' => 200,
                'BASE_URL' => 'http://www.example.com/index.php/datagrid/',
    
            ) ,
            'header' => array(
                'FIELD_NAME_1' => 'FIELD 1',
                'FIELD_NAME_2' => 'FIELD 2',
                'FIELD_NAME_3' => 'FIELD 3',
                'FIELD_NAME_4' => 'FIELD 4',
                'FIELD_NAME_5' => 'ACTION',
            ) ,
            'grid' => array(
                        'Row1' => array(
                            'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
                                'FIELD_ID' => 'Row_Id'),
                        'Row2' => array(
                            'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
                                'FIELD_ID' => 'Row_Id'),
                        'Row3' => array(
                            'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
                                'FIELD_ID' => 'Row_Id'),
                        'Row4' => array(
                            'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
                                'FIELD_ID' => 'Row_Id'),
                        'Row5' => array(
                            'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
                                'FIELD_ID' => 'Row_Id'),
                        'Row6' => array(
                            'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
                                'FIELD_ID' => 'Row_Id'),
                        'Row6' => array(
                            'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
                                'FIELD_ID' => 'Row_Id'),
                        'Row7' => array(
                            'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
                                'FIELD_ID' => 'Row_Id'),
                        'Row8' => array(
                            'FIELD_NAME1' => 'RowField 1', 'FIELD_NAME2' => 'RowField 2', 'FIELD_NAME3' => 'RowField 3','FIELD_NAME4' => 'RowField 4',
                                'FIELD_ID' => 'Row_Id'),
                )
        );
    
    
        foreach ($tableData['header'] as $arrayvalue)
        {
            array_push($tableheader, $arrayvalue);
        }
    
        $tmpl = array ( 'table_open'  => '<table border="1" cellpadding="2" cellspacing="1" class="gridtable">' );
        $this->table->set_template($tmpl);
        $this->table->set_empty(" ");
        $this->table->set_caption($tableData['tblinfo']['CAPTION']);
        $this->table->set_heading($tableheader);
    
    
        foreach ($tableData['grid'] as $arrayvalue)
        {
    
            if (is_array($arrayvalue))
                {
                    //array_walk($arrayvalue, create_function('&$el, $v', 'return $el == "FIELD_ID" ? $v = achor($v, "Edit") : $v; '));
                    $tablebody[] = array_values($arrayvalue);
                }
            else { $tablebody[] = $arrayvalue; }
    
        }
    
    
        echo $this->table->generate($tablebody);
    
        // Create Paging
        $paging['base_url'] = $tableData['tblinfo']['BASE_URL'];
        $paging['total_rows'] = $tableData['tblinfo']['TOTAL_ROWS'];
        $paging['per_page'] = $tableData['tblinfo']['PER_PAGE'];
    
        $this->pagination->initialize($paging);
        //print_r($paging);
        echo $this->pagination->create_links();
    
    
        }//endIndex
    
    
    }
    ?>
  • #30 / Feb 29, 2008 6:17am

    Atasa

    29 posts

    P.S.
    Of course the code is in a controller to run and see the example table.

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

ExpressionEngine News!

#eecms, #events, #releases