Welcome Guest, Not a member yet? Register   Sign In
Figuring out context
#1

[eluser]Matt Bausch[/eluser]
So I have a site that I'm trying to integrate CodeIgniter into. All the pages start with an include to a different php page and the template is built by calling functions in that include file. (i.e. page_start("header"); ) That doesn't work when I try it in my views. I assume it's because the globals aren't really global when called from a view. What should I do?
#2

[eluser]TheFuzzy0ne[/eluser]
Duplicate the header file as a view, and load that.
#3

[eluser]Matt Bausch[/eluser]
You mean the include file? I don't understand why it would work if the php code is directly in the view but won't work if it's in an include_once file.
#4

[eluser]Jondolar[/eluser]
Create a view file with your header information. From your controller, load the header view, then load your page view (then, possibly your footer view if you have one). That would be a typical way to integrate the site into CI (I'm sure there are other ways too).
#5

[eluser]Matt Bausch[/eluser]
It's not simply a header file. I have many functions in my include file. Among them are security verification and other helpful functions. One of these functions dynamically creates everything up to the first <body> tag. So a typical page looks like this:
Code:
<?
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/include.php");
page_start("Login");
?>
html content goes here
This doesn't work from codeigniter because the global variables set at the beginning of include.php are no longer global, whether I load them from the controller or from the view. Maybe a better question would be...where in codeigniter do I set global variables and ensure that the session is always initialized?
#6

[eluser]TheFuzzy0ne[/eluser]
All these "helpful functions" can be exported to a helper/library, and your controller can be responsible for validating. You view should simply be HTML, and a tiny bit of PHP for echoing variables, and formatting them with simple constructs such as if, foreach, while and so on. One of the key ideas behind MVC is that you keep your presentational layer separate from the rest of your app.




Theme © iAndrew 2016 - Forum software by © MyBB