Welcome Guest, Not a member yet? Register   Sign In
$data array elements aren't 'picked up' in my View 'header.php' file
#1

[eluser]stormbytes[/eluser]
I'm passing a regular $data array to my view. Rather then loading the view directly, I'm loading a template which in turn loads header/content/footer.php.

The elements of my $data array resolve without a problem in the content.php part of the template, but for some reason they just don't work in the header.php.

I'm baffled because all 3 template files are essentially called at the same time.

Insights?
#2

[eluser]LuckyFella73[/eluser]
Your code?

Wink
#3

[eluser]Phil Sturgeon[/eluser]
You are using non-standard code and not showing us what it is, so we can't do much to help you.
#4

[eluser]stormbytes[/eluser]
Sorry about that..
Controller
Code:
class Asset extends Controller
{

    function __construct()
    {
        
        parent::Controller();

        $this->load->model('mod_asset');
        
    }

    function details($asset_id = FALSE)
    {
        /**
         * @todo Change $foo to something normal. Refactor this.
         */
        if (!$asset_id) redirect(base_url().'catalog');
        
        $foo = $this->mod_asset->get_asset($asset_id);
        
        if(!$foo) redirect(base_url().'catalog');
        
        $data = array(
            
            'page_title'    =>  'Details',
            'page_desc'     =>  'Some desciption',
            'asset'         =>  $foo,
            'content'       =>  'view_asset'
            
            );
            
        $this->load->view('template', $data);
    
    }

}

The variables (array elements) I'm trying to call from header.php are within the $foo array().
#5

[eluser]Phil Sturgeon[/eluser]
Could you also show your template view?
#6

[eluser]stormbytes[/eluser]
Template View is just this:
Code:
<?php $this->load->view('includes/inc_header'); ?>

<?php $this->load->view($content); ?>

<?php $this->load->view('includes
#7

[eluser]Phil Sturgeon[/eluser]
Try this instead:

Code:
class Asset extends Controller
{
    function __construct()
    {
        parent::Controller();

        $this->load->model('mod_asset');
    }

    function details($asset_id = FALSE)
    {
        /**
         * @todo Change $foo to something normal. Refactor this.
         */
        $asset_id OR redirect('catalog');
        
        $foo = $this->mod_asset->get_asset($asset_id) OR redirect('catalog');
        
        $this->load->vars(array(
            
            'page_title'    =>  'Details',
            'page_desc'     =>  'Some desciption',
            'asset'         =>  $foo,
            'content'       =>  'view_asset'
            
        ));
            
        $this->load->view('template');
    
    }

}
#8

[eluser]stormbytes[/eluser]
Speechless Smile

Will try that as soon as I roll out of bed tomorrow!

Oh.. Just re-read your blog posts on CI2. Downloaded + Playing.

Will move this project to CI2 while its still young, seeing as you outlined the upgrade process so any 4-year-old can pull it off!

Thanks for all your input Phil -

And again - for that RESTful tut on NetTuts. That's gonna be another reason to hound the forums.




Theme © iAndrew 2016 - Forum software by © MyBB