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.

Template controller to grocery CRUD?

June 13, 2011 8:26am

Subscribe [7]
  • #1 / Jun 13, 2011 8:26am

    web-johnny

    235 posts

    Hello there.
    After some revisions of grocery CRUD I see that users don’t want to have by default a template controller into grocery CRUD . I just add a template controller to make the experience of grocery CRUD even easier . (Just one line and the crud is ready). But I realized that most of the users had problem with this. Many conflicts , difficult to understand it etc etc. So I create this poll to see if this is true. If so, to the next version of grocery CRUD I will remove the Template controller library (MY_Loader.php and MY_Output.php).

    Thank you, and of course any other suggestion is more than pleasant.

  • #2 / Jun 14, 2011 12:43am

    timj

    80 posts

    Since the purpose is to permit fast CRUD development, I don’t have a problem with the ready-made templating, although I can see that it does make it more difficult to integrate Grocery CRUD into larger applications.

    Of much more importance sooner, I think, are features like ‘add row’ and row callbacks so that users can use to build TOTAL fields and add navigation features. It’s not really much use as a ‘Grocery CRUD’ if you can’t tally the cost of the groceries.

    I think an ‘add row’ feature would deliver a lot of flexibility and probably get past some of the issues that are annoying others trying to work within the template.

  • #3 / Jun 14, 2011 1:34am

    web-johnny

    235 posts

    You can use : callback_add_field and callback_edit_field for this.
    You can first add a fake “field” to your crud (if you make a callback it will not have any problem). for example :

    $this->grocery_crud->fields('firstname','lastname','email','confirm_email');

    The “confirm_email” doesn’t exist. But when you add a callback for example:

    $this->grocery_crud->callback_add_field('confirm_email',array($this , 'confirmation_email_input'));
    $this->grocery_crud->callback_edit_field('confirm_email',array($this , 'confirmation_email_input'));

    and then your function something like this:

    function confirmation_email_input()
    {
        return '<input type="text" maxlength="50" value="" name="email_confirm" style="width:462px">[removed]...mpla mpla.[removed]';
    }

    Or to add a field of your own and then work with callback_before_insert or callback_before_update. I have many many callbacks I just have to documented with more examples so the users can use them easily. I will have it in mind thanks.

  • #4 / Jun 14, 2011 1:42pm

    timj

    80 posts

    You can use : callback_add_field and callback_edit_field for this.
    You can first add a fake “field” to your crud (if you make a callback it will not have any problem).

    I don’t think you understood my comment.

    You have a column of prices. Of course you can add a fake field to the right of it and build a function to total the entire column of prices. But the TOTAL calculation would have to iterate on every row. And it would be clunky and confusing for users used to how spreadsheets look and work.

    Instead what you’d want is a new row at the bottom where all the column totals may be calculated just once. What would be handy is a ready callback library of basic SQL counting, math [SUM()] and time [NOW()] functions to build these callbacks around.

    For myself, I would like the option of adding a row of navigation callbacks, so that I can, for example, limit the query results based on dates. I realize, again, that I could add a fake field… that would have to iterate on each row instead of just once on one row.

    Good product.

  • #5 / Jun 14, 2011 3:11pm

    web-johnny

    235 posts

    You can use : callback_add_field and callback_edit_field for this.
    You can first add a fake “field” to your crud (if you make a callback it will not have any problem).

    I don’t think you understood my comment.

    You have a column of prices. Of course you can add a fake field to the right of it and build a function to total the entire column of prices. But the TOTAL calculation would have to iterate on every row. And it would be clunky and confusing for users used to how spreadsheets look and work.

    Instead what you’d want is a new row at the bottom where all the column totals may be calculated just once. What would be handy is a ready callback library of basic SQL counting, math [SUM()] and time [NOW()] functions to build these callbacks around.

    For myself, I would like the option of adding a row of navigation callbacks, so that I can, for example, limit the query results based on dates. I realize, again, that I could add a fake field… that would have to iterate on each row instead of just once on one row.

    Good product.

    Now I understood what do you mean. Yes Its a good suggestion and I will added as a future plan . Thanks.

  • #6 / Jun 14, 2011 10:09pm

    fabgonber

    15 posts

    web-johnny,

    An idea…

    public person() {
          // ...
          $crud = new Grocery_Crud();
          $crud->...
          $crud->...
          $mytable = $crud->generate();
          ...
          $data['tablecrud'] = $mytable;
          $this->load->view('myview',$data);
    }

    And with this i can put the CRUD in my view 😊

    Today i solve the problem with a modification of the grocery’s template.

  • #7 / Jun 15, 2011 2:32am

    web-johnny

    235 posts

    web-johnny,

    An idea…

    public person() {
          // ...
          $crud = new Grocery_Crud();
          $crud->...
          $crud->...
          $mytable = $crud->generate();
          ...
          $data['tablecrud'] = $mytable;
          $this->load->view('myview',$data);
    }

    And with this i can put the CRUD in my view 😊

    Today i solve the problem with a modification of the grocery’s template.

    I have this example in my website (I just copy the code)

    public person() {
          // ...
          $crud = new Grocery_Crud();
          $crud->...
          $crud->...
          $crud->render();//Don't be afraid there will not echo anything :blush:
    
                $js_array = $this->_get_all_javascripts();
                $css_array = $this->_get_all_css();
                $views = $this->_get_all_views();
                
                $data = array('js_array' => $js_array , 'css_array' => $css_array, 'tablecrud' => $views);
                
                $this->load->view('myview',$data); //And tadaaaa
    
    }
       
        protected function _get_all_javascripts()
        { 
            return $this->load->get_js_files();
        }
        
        protected function _get_all_css()
        { 
            return $this->load->get_css_files();
        }
    
        protected function _get_all_views()
        { 
            $output = $this->output->get_output();
            $this->output->final_output = '';//As you get the output you don't need anymore the output to view it automatically
            return $output;
        }    
        
        ...........etc
    }

    if something like this appears

    Fatal error: Cannot access protected property
    MY_Output::$final_output

    which happens in this line:

    $this->output->final_output = '';

    so just make the variable public in the CI_Output Class.

  • #8 / Jun 15, 2011 11:03am

    felix_

    22 posts

    Hey,
    i tried to add groceryCRUD in the way you described it…

    <?php
        foreach ($js_array as $js) {
            echo "[removed][removed]\n";
        }
        foreach ($css_array as $css) {
            echo "<link type=\"text/css\" href=\"".$css."\" rel=\"stylesheet\" />\n";
        }
        echo $grocery_crud_as_string;
    ?>

    thats what my test view looks like… just works fine
    but when i try to update/insert an entry i get an error:

    POST <a href="http://localhost/site/users/admin/update_validation">http://localhost/site/users/admin/update_validation</a> 500 (Internal Server Error)

    and when i click on this error (via chrome)

    [removed]window["_gaUserPrefs"] = { ioo : function() { return true; } }[removed][removed]window.script1308146381998=1;[removed]

    another thing is the jquery loading… im already loading jquery in the header of my page and grocery will also load it… is there an easy way to stop grocery loading its own jquery?

  • #9 / Jun 16, 2011 12:52am

    a/\ekc

    6 posts

    if something like this appears

    Fatal error: Cannot access protected property
    MY_Output::$final_output

    which happens in this line:

    $this->output->final_output = '';

    so just make the variable public in the CI_Output Class.

    It’s no good way to change the core files I think.
    I can forget in the future, that something was changed in core files. And after update of the core files the same error will be.
    I voted for default template, but would like to see it more flexible.
    In grocery_crud.php file functions have such code parts

    $ci->load->js('public/grocery_crud/js/jquery_plugins/.../somefile.js');
    $ci->load->css('public/grocery_crud/css/..../somefile.css');          ');

    And this make me always have “public” folder in top of web directory
    To change template folder i have to go in application/core/MY_Output and change

    const TEMPLATE_ROOT = "templates/";

    It’s no flexible

    My way.
    I had a project with cms template (application/views/cms/template.php)

    <?php
    //template without CRUD
    $this->load->view('cms/header');  
    if (isset($content)) echo $content;
    $this->load->view('cms/footer');
    ?>

    And want to use grocery crud. So almost the same template was created in “templates/cms/template.php”.

    <?php
    //template for CRUD
    $this->load->view('application/views/cms/header');
    if (isset($content)) echo $content;
    echo $output;
    $this->load->view('application/views/cms/footer');
    ?>

    Both template.php have the same header. So in header.php this code was placed:

    <?php 
    <head>
    ....
    if (isset($crud)) { //check using CRUD 
    foreach($css as $file): ?>
    <link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
    <?php endforeach; ?>
    [removed]var base_url = '<?=base_url()?>';[removed]
    <?php foreach($js as $file): ?>
        [removed][removed]
    <?php endforeach; 
    }
    ...
    </head>
    ?>

    In cms controller

    public function my_table() {
    //use crud template
    $this->load->add_package_path(APPPATH.'third_party/grocery_crud/');
    $this->output->set_template('cms');
    $this->load->library('grocery_CRUD');
          
    $crud = new grocery_CRUD();
    $crud->set_theme('datatables');
    $crud->set_table('my_table');
    $this->output->set_output_data('crud','yes'); //for header.php
    $this->output->set_output_data('content','some additional content before crud table');
    $crud->render();
    
    }

    All works fine but small inconvenience to have two templates

  • #10 / Jun 16, 2011 2:20am

    web-johnny

    235 posts

    Hey,
    i tried to add groceryCRUD in the way you described it…

    <?php
        foreach ($js_array as $js) {
            echo "[removed][removed]\n";
        }
        foreach ($css_array as $css) {
            echo "<link type=\"text/css\" href=\"".$css."\" rel=\"stylesheet\" />\n";
        }
        echo $grocery_crud_as_string;
    ?>

    thats what my test view looks like… just works fine
    but when i try to update/insert an entry i get an error:

    POST <a href="http://localhost/site/users/admin/update_validation">http://localhost/site/users/admin/update_validation</a> 500 (Internal Server Error)

    and when i click on this error (via chrome)

    [removed]window["_gaUserPrefs"] = { ioo : function() { return true; } }[removed][removed]window.script1308146381998=1;[removed]

    another thing is the jquery loading… im already loading jquery in the header of my page and grocery will also load it… is there an easy way to stop grocery loading its own jquery?

    Parhaps this is a javascript error. I actually don’t know what cause this error. A simple way could to unset the jquery could be this :

    protected function _get_all_javascripts()
        { 
            $javascripts = $this->load->get_js_files();
            
            foreach($javascripts as $num_row => $javascript)
            {
                if($javascript == 'public/grocery_crud/themes/datatables/js/jquery-1.5.1.min.js')
                {
                    unset($javascripts[$num_row]);
                }
            }
            
            return $javascripts;
        }
  • #11 / Jun 16, 2011 2:29am

    web-johnny

    235 posts

    @a/\ekc This is why I’m having this poll 😊 . Probably in the next version (1.1) I will remove the two libraries so the users will be more flexible as you said. The next version (probably) will work with views so this will make it automatically more flexible.

  • #12 / Jun 16, 2011 3:24am

    felix_

    22 posts

    @web-jonny
    ok this works.. so i dont have double loaded jquery but i still dont know what causes the js error :/

  • #13 / Jun 16, 2011 4:00am

    a/\ekc

    6 posts

    a/\ekc This is why I’m having this poll 😊 . Probably in the next version (1.1) I will remove the two libraries so the users will be more flexible as you said. The next version (probably) will work with views so this will make it automatically more flexible.

    As for me, there was no problem put grocery CRUD dataset in my view
    I did in version 1.0.3 so (experimental)

    I had only MY_Loader.php (without MY_Output.php)

    in controller

    function test_crud_in_view(){
    
            $this->load->add_package_path(APPPATH.'third_party/grocery_crud/');
           // remove all output 
           // $this->output->set_template('custom_cms');
            $this->load->library('grocery_CRUD');
          
            $crud = new grocery_CRUD();
            
            $crud->set_table('test_table');
            
            //remove render to avoid echo cruddataset before all view content
            //$crud->render();
    
            $data[$crud] = &$crud;
            $this->load->view('template',$data);
    
    }

    so in view/template.php

    <?php
    //template with CRUD
    $this->load->view('header');  
    
    if (isset($content)) echo $content;
    //render CRUD if needed
    if (isset($crud) && is_object($crud))) 
    $crud->render();
    
    $this->load->view('footer');
    ?>

    and so only one problem exists to quickly get correct CSS and JavaScript libraries for concrete theme
    And i think this is your development priority 😉

  • #14 / Jun 16, 2011 2:01pm

    web-johnny

    235 posts

    Did you read the installation instructions for to not work with templates ? Is if you scroll down a bit on http://www.grocerycrud.com/crud/view/codeigniter_installation . But you still need the MY_Loader.php for now this version of grocery crud.

  • #15 / Jun 17, 2011 3:52am

    a/\ekc

    6 posts

    Did you read the installation instructions for to not work with templates ? Is if you scroll down a bit on http://www.grocerycrud.com/crud/view/codeigniter_installation . But you still need the MY_Loader.php for now this version of grocery crud.

    I see that your main aim is completely remove MY_Output and MY_Loader.
    As for me, the main problem is to have “public” or “template” folder only in top of web folder node without any other possibilities to rename or move them to another place them quickly. In my project i can use such folders for other goals already.
    So i voted for template controller, but would like to see it more flexible in this.
    Think, we have understood one another.
    Best wishes.

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

ExpressionEngine News!

#eecms, #events, #releases