⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Loading Custom views and other data



bluepicaso
  • profile picture
  • Member

Posted 19 March 2012 - 09:17 AM

hey I am new here, I have been using codeigniter for a long time and this was my referred to me by a friend.
We Grocery CRUD is just awesome, i came accross a small problem.
i was able to load output from CRUD but there were situationd where i wanted to load a new view.

[quote]The obvious solution is to create a new view file. [/quote]

a small solution from me

The simple example to load extra data as give on the website itself

$crud = new grocery_CRUD();
$crud->set_theme('flexigrid');
$crud->set_table('scholarship');
$crud->set_relation('schCollege', 'university', 'name');
$output = $crud->render();
$data['title'] = "Manage Scholarship";
$output = array_merge($data,(array)$output);
$this->_outputData($output);


Loading my custom view

$data['title'] = "Insert via CSV";
$data['content'] = 'csvUploader'; // <----------------- the file i need as a view
$this->_outputData($data);



My Template

<?php $this->load->view('includes/admin_header');?>
<div id="dataContainer">
<h2>
<?=$title?>
</h2>
<?php
if(isset($output))
{
echo $output;
}
else
{
$this->load->view($content);
}
?>
</div>
<?php $this->load->view('includes/admin_footer');?>



Hope it helps

Thank you

DirectWeb
  • profile picture
  • Member

Posted 21 March 2012 - 11:34 AM

First and foremost you're including template vars (tv).
Therefore I've created in the Class [b]grocery_Layout[/b] (file: libraries/grocery_crud.php) some functions and the var tvs:



protected $tvs = array();

[....]

public function set_tv($name, $val)
{
$this->tvs[$name] = $val;
}
public function get_tvs()
{
return $this->tvs;
}


and added some Code to the function [b]get_layout[/b]:

protected function get_layout()
{
$js_files = $this->get_js_files();
$css_files = $this->get_css_files();
$tvs = $this->get_tvs();

if($this->unset_jquery)
unset($js_files['763b4d272e158bdb8ed5a12a1824c94f494954bd']);

if($this->echo_and_die === false)
{
return (object)array('output' => $this->views_as_string, 'js_files' => $js_files, 'css_files' => $css_files, 'tv' => $tvs);
}
elseif($this->echo_and_die === true)
{
echo $this->views_as_string;
die();
}
}


So now I can include new vars to the Views by setting them like the following lines:

$crud = new grocery_CRUD();
$crud->set_tv("title", "Some Title");


In the Template I'll get them by:

<?php echo $tv['title'] ?>


Hopefully that helps and makes the code a little bit more readable.Maybe that can be put in the "Future Features" or the actual branch of development.