I would suggest what I do always with views, Use a template with header, content, footer. (after the theory I'll explain how to use it with grocery crud)
first: The template: (template.php)
<?php
$this->load->view('includes/header');
$this->load->view($content_view);
$this->load->view('includes/footer');
With this, we have a standard template.
To load a view, use this code:
class Users enxtends CI_Controller {
//any controller...
public function login(){ //any function...
$data['content_view']='users/login';
$this->load->view('template',$data);
}
This way, you are loading a view within a template, passing extra data to the template (second parameter $data).
With this logic, you don't need to change grocery-crud's core, try this instead:
Header: include crud's styles and javascripts. (includes/header.php)
<?php
if(isset($css_files)){
foreach($css_files as $style){
echo '<link href="'.$style.'" rel="stylesheet"/>';
}
}
if(isset($js_files)){
foreach($js_files as $script){
echo '<script src="'.$script.'" type="text/javascript"></script>';
}
}
crud_content_view: echo the output (crud_content_view.php)
<?php echo $output;?>
Controller/function (crud_controller.php)
·
·
·
$output=$crud->render(); //$output is an object with attributes: js_files,css_files,output
$output->content_view='crud_content_view'; //we add a new attribute called content_view
//because our template loads the view content_view for the content.
//if we want to pass data, try this.
$data=array();
$data['variable1']='variable_value';
$data['variable2']=12;
$data['variable3']=array('subvariable1'=>'value1-1','subariable2'=>'value1-2');
//etc, then assign data to output.
$output->data=$data;
$this->load->view('template',$output);
Then to access data in the view try this: (in crud_content_view.php)
echo $data['variable1'];
echo $data['variable2'];
foreach($data['variable3'] as $var3){
echo $var3;
}
This is good practice from codeigniter's manual, try to not alter the crud library core.
Regards