Data in controller is not being passed to view

I'm stuck on a rudimentary question that's just boggling my mind right now. I'm setting $vars['catName'] in my controller and I keep getting the error Undefined Index : catName". The $vars['patterns'] is accessible from the view and I know that $vars['catName'] contains data because my page title contains the correct info.

Controller:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); Class Patterns extends CI_Controller { function index($categoryId = null) { $vars['catName'] = ""; $this->load->model('patterns_access_model'); if(!is_null($categoryId)) { $vars['patterns'] = $this->patterns_access_model->get_patterns_by_id($categoryId); $vars['catName'] = $this->patterns_access_model->get_category_by_id($categoryId); } // set your variables $vars = array('page_title' => 'Check Out Our List Of '.$vars['catName'].' Patterns | Campbell Custom Coatings'); // use Fuel_page to render so it will grab all opt-in variables and do any necessary parsing $page_init = array('location' => 'patterns', 'render_mode' => 'cms'); $this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init); $this->fuel_page->add_variables($vars); $this->fuel_page->render(); } }


I have this in my view:
<h1>CatName = <?php echo $catName; ?></h1>

and when I import it into fuel, the dwoo parsing looks like this:
<h1>CatName = {$catName}</h1>

Am i missing something?

Comments

  • edited 10:39PM
    That error is happening in your view file correct? Are you perhaps using something like <?=$vars['catName']?> somewhere in your view file?
  • edited 10:39PM
    Yes it's happening in my view file. No i'm only doing <?php echo $catName; ?>.
  • edited 10:39PM
    I figured it out. This line $vars = array('page_title' => 'Check Out Our List Of '.$vars['catName'].' Patterns | Campbell Custom Coatings'); overrights my vars['catName'] declaration.

    I should have gotten some sleep before posting on here. Thanks anyways.
Sign In or Register to comment.