How to structure this code? |
[eluser]behnampmdg3[/eluser]
Hi I have this piece of code in all my controllers. Where is the best place to put it so I dont repeat myself? Thanks Code: $this->logged = $this->session->userdata['logged_data']['logged_in']; And this is the whole class as an example Code: class Deals extends CI_Controller {
[eluser]Otemu[/eluser]
Hi, You could use a base controller example here or you could use custom library however you probably have something like $this->mycustomlib->dosomething(); in all your controllers.
[eluser]behnampmdg3[/eluser]
Hi; Thanks for you reply. It works in some pages! In some pages I get this notice! Can you tell why? It's strange. Quote:A PHP Error was encountered Code: class Header
[eluser]Rolly1971[/eluser]
this is what i do. in folder: application/core create file: MY_Controller.php in this file add: Code: defined('BASEPATH') OR exit('No direct script access allowed'); you can then use this 'base' controller to put in any code/functions that will be common to all your controllers. then you just need to adjust your controllers in application/controllers to inherit from this new base controller. example: Code: defined('BASEPATH') OR exit('No direct script access allowed'); hopefully this points you in the write direction |
Welcome Guest, Not a member yet? Register Sign In |