CodeIgniter Forums
pass values from controller to constructor - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: pass values from controller to constructor (/showthread.php?tid=56130)



pass values from controller to constructor - El Forum - 11-28-2012

[eluser]livewirerules[/eluser]
im trying to set a title and meta description for each function in my controller and the below doesnt seem to be working.

below is the code im using

Code:
function __construct()
{

    parent::__construct();

    $info['title'] = 'No title';
   $info['descrip'] = 'No description';
    $this->load->view('include/header',$info);
}


function be_cool()
{

    $info['title'] = 'This is the be cool title';
    $info['descrip'] = 'This is the be cool description';
    $info['body'] = 'template/becool';
    

    $this->load->view('include/template',$info);
}

function be_hot()
{
   $info['title'] = 'This is the be hot title';
    $info['descrip'] = 'This is the be cool description';

    $info['body'] = 'template/behot';

    $this->load->view('include/template',$info);
}

can someone please help he how to get this working


pass values from controller to constructor - El Forum - 11-28-2012

[eluser]jprateragg[/eluser]
Can you post your view(s) (include/template; include/header)?


pass values from controller to constructor - El Forum - 11-28-2012

[eluser]livewirerules[/eluser]
template
Code:
$this->load->view($body);
$this->load->view('includes/footer');

header
Code:
<!DOCTYPE HTML>
&lt;html lang="en-US"&gt;
&lt;head&gt;
&lt;meta charset="UTF-8" /&gt;
&lt;meta name="viewport" c initial-scale=1.0" /&gt;
&lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
      &lt;meta name="description" c echo $descrip; ?&gt;"&gt;
&lt;!--[if lt IE 9]>
  [removed][removed]
  [removed][removed]
  [removed][removed]
<![endif]--&gt;
&lt;!-- The Fonts
&lt;link href="http://fonts.googleapis.com/css?family=Oswald|Droid+Sans:400,700" rel="stylesheet" /&gt;
  --&gt;
  
&lt;!-- The Main CSS File --&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url();?&gt;assets/css/style.css" /&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url();?&gt;assets/fonts/font.css" /&gt;
  &lt;link rel="stylesheet" href="&lt;?php echo base_url();?&gt;assets/css/validationEngine.jquery.css" type="text/css"/&gt;
&lt;/head&gt;



pass values from controller to constructor - El Forum - 11-28-2012

[eluser]jesterhead[/eluser]
your loading your header before the appropriate title and description is set in your functions.

put
Code:
$this->load->view('include/header',array('title' => $title, 'descrip' => $descrip));
in your template