need to include functions.php but it doesnt work |
[eluser]gloosemo[/eluser]
Hi I'm definitaly a PHP beginner I have 2 pages, a controller and a view. the controller loads the view. the controller contains some functions that are called via ajax. Some of the code contained in these controller functions is very similar to code contained in the view. Basically I have to write the code out twice. what i want to do is create a page functions.php and include it at the top of the controller, then i can just enter stuff there once and access it both later on in the controller or in the view (right?) The problem is that when i require_once functions.php, if i try to use CI statments like $this->session->userdata('abc') inside functions.php i get an error saying i'm using $this outside of an object context. I doubt even if it was in context it would properly access the session class. this is the functions.php code: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); How can i make this work? Thanks
[eluser]Aken[/eluser]
Use helpers. http://ellislab.com/codeigniter/user-gui...lpers.html
[eluser]PhilTem[/eluser]
And don't forget you cannot use the object operator $this-> if you're not in object-mode. So your function ini_page() will produce an error when it's being compiled saying it can't be processed due to missing object-mode ![]()
[eluser]Aken[/eluser]
You can, however, use the CI object in your helpers by assigning the CI super object to a variable by reference. See "Utilizing CodeIgniter Resources within Your Library" on the this page. |
Welcome Guest, Not a member yet? Register Sign In |