• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making model that hold important data on all controllers


I am new in Codeigniter 3 i get into some points where i stuck.

In my old php code (without framework), website structure i had was one file index.php that was holding all logged in user data, checking if user is logged, website settings, etc. Each page was different ‘case’ which was loaded file that was matching ‘case’ value in index.php.

Now when i started to work in Codeigniter i see that this is complex to make, at least for me.

For example i made few controllers, Login, Home, Profile, Accounts and in constructor of each controller i loaded website settings, check if user is logged in and many other stuff like on old website i had, but this is too much code to edit if i need to make some changes but i don’t know other way of doing it.

I saw that you can make like main model where you can put all those stuff and call that main model by extending class with that model.

What i want to know is there any other way to have all those settings and checking loaded in every controller, i want to keep extending CI_Controller for each new Controller i made if that is possible.

You can make a new controller named User_Controller and Admin_Controller depending on access type you want to require. And those two are extending CI_Controller.

Account_Controller extends User_Controller etc.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.