Welcome Guest, Not a member yet? Register   Sign In
load->view and include
#1

[eluser]al404[/eluser]
it is my first site, and i'm doing a

template.php
/include/header.php

in the view folder

in the header file i set some variables that i may need to use later in the body of the page and i did include

load->view('/include/header.php');

into template.php

but i notice that variable set in header are not accessible in template body (after load->view('/include/header.php'))

so i was wondering what is the difference if i use in templae.php

include('/include/header.php');

vs

load->view('/include/header.php');
#2

[eluser]VirtualDevel[/eluser]
Can you show us the /include/header.php file? Are you sure the vars are set before calling load->view?
#3

[eluser]al404[/eluser]
for example:

*** header.php ********************************************************************

<title>test script</title>
<?php $testvar="output my test var"; ?>


*** end header.php ****************************************************************


*** template.php ********************************************************************

<?php if (!defined('BASEPATH')) exit('No direct script access allowed!'); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;?php $this->load->view("common/header.php"); ?&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php echo $testvar; ?&gt;
&lt;/body&gt;
&lt;/html&gt;

*** end template.php ****************************************************************


A PHP Error was encountered
Severity: Notice
Message: Undefined variable: testvar
Filename: views/template.php




Theme © iAndrew 2016 - Forum software by © MyBB