CodeIgniter Forums
Template controller to grocery CRUD? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Template controller to grocery CRUD? (/showthread.php?tid=42617)

Pages: 1 2


Template controller to grocery CRUD? - El Forum - 06-13-2011

[eluser]web-johnny[/eluser]
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.


Template controller to grocery CRUD? - El Forum - 06-13-2011

[eluser]timj[/eluser]
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.


Template controller to grocery CRUD? - El Forum - 06-13-2011

[eluser]web-johnny[/eluser]
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 :
Code:
$this->grocery_crud->fields('firstname','lastname','email','confirm_email');
The "confirm_email" doesn't exist. But when you add a callback for example:
Code:
$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:
Code:
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.


Template controller to grocery CRUD? - El Forum - 06-14-2011

[eluser]timj[/eluser]
[quote author="web-johnny" date="1308044082"]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).[/quote]

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.


Template controller to grocery CRUD? - El Forum - 06-14-2011

[eluser]web-johnny[/eluser]
[quote author="timj" date="1308087746"][quote author="web-johnny" date="1308044082"]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).[/quote]

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.[/quote] Now I understood what do you mean. Yes Its a good suggestion and I will added as a future plan . Thanks.


Template controller to grocery CRUD? - El Forum - 06-14-2011

[eluser]fabgonber[/eluser]
web-johnny,

An idea...
Code:
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 Smile

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


Template controller to grocery CRUD? - El Forum - 06-14-2011

[eluser]web-johnny[/eluser]
[quote author="fabgonber" date="1308118193"]web-johnny,

An idea...
Code:
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 Smile

Today i solve the problem with a modification of the grocery's template.[/quote]
I have this example in my website (I just copy the code)
Code:
public person() {
      // ...
      $crud = new Grocery_Crud();
      $crud->...
      $crud->...
      $crud->render();//Don't be afraid there will not echo anything :-)

            $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
Code:
Fatal error: Cannot access protected property
MY_Output::$final_output
which happens in this line:
Code:
$this->output->final_output = '';

so just make the variable public in the CI_Output Class.


Template controller to grocery CRUD? - El Forum - 06-15-2011

[eluser]felix_[/eluser]
Hey,
i tried to add groceryCRUD in the way you described it...

Code:
<?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:
Code:
POST http://localhost/site/users/admin/update_validation 500 (Internal Server Error)
and when i click on this error (via chrome)
Code:
[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?


Template controller to grocery CRUD? - El Forum - 06-15-2011

[eluser]a/\ekc[/eluser]
Quote:if something like this appears
Code:
Fatal error: Cannot access protected property
MY_Output::$final_output
which happens in this line:
Code:
$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
Code:
$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
Code:
const TEMPLATE_ROOT = "templates/";
It's no flexible

My way.
I had a project with cms template (application/views/cms/template.php)
Code:
<?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".

Code:
<?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:
Code:
<?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

Code:
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


Template controller to grocery CRUD? - El Forum - 06-15-2011

[eluser]web-johnny[/eluser]
[quote author="felix_" date="1308164616"]Hey,
i tried to add groceryCRUD in the way you described it...

Code:
<?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:
Code:
POST http://localhost/site/users/admin/update_validation 500 (Internal Server Error)
and when i click on this error (via chrome)
Code:
[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?[/quote]

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 :
Code:
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;
    }