Welcome Guest, Not a member yet? Register   Sign In
public var in extended core class not visible in controller
#1

[eluser]potion[/eluser]
Why can't my controller see the public var?

application/core/MY_Controller.php
Code:
<?php
class MY_Controller extends CI_Controller
{
public $template_data = array();

function construct()
{
  parent::__construct();
  
  $this->template_data['page_title'] = 'My Site';
  $this->template_data['stylesheets'][] = 'css/styles.css';
  $this->template_data['javascripts'][] = 'js/functions.js';
}

}

application/controllers/home.php
Code:
<?php
class Home extends MY_Controller
{
function index()
{
  $this->template_data['page_title'] .= " - Home";
  $this->template_data['body_id'] = "body_home";
  $content_data['some_var'] = 'some data for the content view';
    
  // Render View
  $this->template_data['header_view'] = $this->load->view( 'header_view', '', true );
  $this->template_data['content_view'] = $this->load->view( 'home/content', $content_data, true );
  $this->template_data['footer_view'] = $this->load->view( 'footer_view', '', true );
  $this->load->view( 'page_template_home', $this->template_data );
}

}

When I run it I get a PHP error:
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined index: page_title
Filename: controllers/home.php
Line Number: 6

info: I'm updating from CI 1.6.3 to 2.1.0 - In 1.6.3 MY_Controller was an extension to Controller and resided in application/libraries - In 2.1.0 MY_Controller is an extension to CI_Controller and resides in application/core - I can't spot my faux pas... please verify.

Denis
#2

[eluser]InsiteFX[/eluser]
I think you need to add the constructor in your home controller!
#3

[eluser]potion[/eluser]
Nope. Putting the constructor in home.php didn't change anything.
#4

[eluser]Aken[/eluser]
Your construct function in MY_Controller doesn't have the two underscores on it, so it isn't being called, so it is not setting the page_title item in your data array.
#5

[eluser]potion[/eluser]
[quote author="Aken" date="1328913772"]Your construct function... ...doesn't have the two underscores on it...[/quote]
Right on Aken! I'm so embarrassed! Amazing how we over-complicate things and fail to spot the obvious!
#6

[eluser]Aken[/eluser]
Happens to us all now and then.




Theme © iAndrew 2016 - Forum software by © MyBB