[eluser]lama[/eluser]
Hello everybody
I have a little problem...
I search in documentation but I found nothing...
I have a big project with CodeIgniter. I set a default layout where I include my views. Views are define with controller but I have to run a function on all page but I don't know how can I do it...
This function will show information to the user in the layout before including my view.
So I hope that I was clear... I'm blocked...
Thanks
Good night
[eluser]adamck[/eluser]
I dont really understand.
You can run CI functions within a view, so a view can load another view etc...
Also you can pass data to a view, an array to a view or you can use the template parser.
You can put a function within a model, auto load the model and call that model function within each controller if you want...
It depends on the function your doing and what its going to do?
You need to provide more info!
[eluser]PhilTem[/eluser]
search for: MY_Controller if the function needs to be run from the controller
or search for: helpers if the function needs can be run from the view
[eluser]lama[/eluser]
The function needs to run before the controller and before the view.
I'm working on a little php game where the user makes x gold per hour. So I need to calcul the gold production before executing the view. And after in the view I show the gold.
Maybe I can include my code in __construct method of all controllers but I ask if there is a better way to do it.
Is it more clear ? :p
[eluser]PhilTem[/eluser]
That's just what I meant with telling you to search for MY_Controller: It will help you to run methods that need to be run on every page request made to any controller by injecting these methods into the __construct()-method.
[eluser]lama[/eluser]
I tried with your method but it doesn't work when I put my controller in library folder, I have a critical error "class not found".
But when I put it in core folder I have no error but its seems that the controller do nothing.... or maybe session var doesn't work.
I tried the controller as a basic controller and it's working so I think that the problem isn't the controller code but the way I use it.
[eluser]CroNiX[/eluser]
Yes, read the user guide on:
Creating Core Classes
Creating Libraries
Things have to go in specific places, depending what they are.
Extending CORE classes (prefixed with MY_) (things in /system/core) go in /application/core
Extending CORE libraries (prefixed with MY_) (things in /system/libraries) go in /application/libraries