⚠ 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

Pass session value to view



soltic
  • profile picture
  • Member

Posted 28 July 2013 - 07:06 AM

With codeigniter I can spend 

$ data ['login'] = $ this-> session-> userdata ('login');
 to view and display the value with this code:
$ data ['login'] = $ this-> session-> userdata ('login');
$ data ['content'] = 'backoffice / Login_frm;
$ this-> load-> view ('templates / template', $ data);
 
How do they do the same thing with grocerycrud using this code:
TypeStructure function ()
   {
         grocery_CRUD $ crud = new ();
         $ this-> grocery_crud-> set_table ('StructureType');
$this->grocery_crud->unset_add_fields('Createur','InsertDate','ModificationDate','DernierModificateur');
        
         $ this-> grocery_crud-> set_theme ('Flexigrid');
$ this-> grocery_crud-> change_field_type ('Active', 'true');
         $ this-> grocery_crud-> callback_delete (array ($ this, 'delete_typestructure'));
         $ this-> grocery_crud-> set_relation ('Niveau_ID', 'Level', 'Niveau_ID');
         $ this-> grocery_crud-> callback_after_update (array ($ this, 'log_typestructure_after_update'));
         $ output = $ this-> grocery_crud-> render ();
         $ this-> _typestucture_output ($ output);
   }
  
   _typestucture_output function ($ output = null)


     {
        $ output-> content = 'backoffice / typestructure;
        $ this-> load-> view ('templates / backoffice / template', $ output);
     }

davidoster
  • profile picture
  • Member

Posted 28 July 2013 - 10:25 AM

Hello and welcome to the forums [member=soltic].

Probably the best way is to modify the example.php file under application/views and separate it to logical views, e.g.

head.php, header.php,menu.php,content.php,footer.php

 

and then witihn your output function call these views,

 

$this->load->view('head', $data_head);

$this->load->view('header', $data_header);

$this->load->view('menu', $data_menu);

$this->load->view('content', $data_content); // this could be the output from $this->grocery_crud->render();

$this->load->view('footer', $data_footer);

 

UPDATE: Of course you need to know how to pass some data from the output of the Grocery CRUD's render function because it contains the js and css files.

Just see the index() controller function of the example.php and you will know what to do.


soltic
  • profile picture
  • Member

Posted 14 August 2013 - 10:34 AM

i had already do the template but my problem is to print the uername in the view same as i did it in  basic codeigniter developpement


Amit Shah
  • profile picture
  • Member

Posted 17 August 2013 - 06:55 AM

Hi there,

 

Well you still can do the same with grocery crud

function pending_customers()
{
		try{
			$crud = new Grocery_crud_with_view();
			$crud->set_table('customers');

......
.....
.....

			$output = $crud->render();
			$data = array();
			$data['active_menu'] = 'Customers';
			$data['page_title'] = 'Customers';
			$output->data=$data;
			$this->load->view('crud',$output);
}

This way, you can pass the relevant data to the gc view also. In with GC view .. the only difference here is ... you can access the active_menu (as in above exampl) by $data['active_menu'] rather than $active_menu ...

Rest .. with grocery crud .. what it requires @its end in the view is the following

....
....
...
foreach($css_files as $file): ?>
	<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($js_files as $file): ?>
	<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>


...
...
...
<?php echo $output; ?>

Now how you adjust your layout across this is all upto you and your skill set.