atomicon / codeigniter-theme

Easily developing themes with all assets at one place
34 stars 26 forks source link

Passing Data #6

Open michaelcummings opened 11 years ago

michaelcummings commented 11 years ago

I keep running into problems passing data to the views in the themes. Am I missing something?

Normally you pass data from your controller to your view by passing your $data[] array, but I can't seem to get this to work like normal. I've tried ever possible method I can think of to get the value out, but I keep getting various different error messages depending on the method.


A PHP Error was encountered

Severity: Notice

Message: Undefined variable: bio

Filename: basic/index.php

Line Number: 78


I get a similar message no matter how I try and access it:

$this->theme->get('bio') $this->get('bio') $this->bio $this->data['bio'] $this->data('bio') $bio

None of these work in my theme view...

Your example themes do not pass variables to the themes so I'm unclear how you're doing accomplishing this...

Maybe I'm missing something simple, but I'm just utterly confused at the moment why I can't get this to work.

elgalesmana commented 11 years ago

hi, you can try this :

edit your theme.php and add this code :

protected $_cvar = array(); // in protected variables

// set data function set_var($data = array()) { $this->_cvar = is_array($data) ? $data : array(); $this->_cvar = array_merge($this->_data, $data); } // return data function show_var($key) {
return $this->_cvar[$key]; }

and you can passing data from your controller :

$data['bio'] = 'biography'; $data['name'] = 'my name'; $this->theme->set_var($data);

and in index.php themes :

<?php echo $this->show_var("name"); ?>