Template Library and DX_Auth Integration |
[eluser]Mithun[/eluser]
I uses DX Auth and Template Library http://www.williamsconcepts.com/ci/codei.../template/ I need set up a layout, there there is a user area that is displayed only for logged users. I have created the curresponding view in views/user_area.php and this view shows logged users name. For getting this I need to setup the following code in every controller constructor. Code: $this->load->library(array('template', 'DX_Auth')); this is my template layout file Code: <html>
[eluser]flaky[/eluser]
Extend the Controller. Use MY_Controller, put the code that you need repeating in the mentioned Controller.
[eluser]Colin Williams[/eluser]
We really, as a community, need to generate a de facto response to this question that comes up 5 times a day in 600 different flavors. The wiki touches on it in a few places but I don't think it's clear enough. Maybe I'll tackle that tonight or tomorrow.
[eluser]Mithun[/eluser]
@flaky, @Colin Williams Thanks Got some stuff from here http://codeigniter.com/wiki/Extending_Co...tionality/ But still some confusion, i need to move my common code to MY_Controller? is it right to edit a file in system folder?
[eluser]Colin Williams[/eluser]
No. Don't touch system code. MY_Controller would exist at application/libraries/MY_Controller.php. Most of your global logic will live in MY_Controller's constructor function, typically getting data and making it available to views through $this->load->vars() or by writing it to a template region. Consider this Code: class MY_Controller extends Controller { And then be sure your Controllers in application/controllers extend MY_Controller, not just Controller (unless you WANT to bypass what MY_Controller does). That's the gist of it.
[eluser]Mithun[/eluser]
As i don't want each unnecessary extra master page template features of MY_Controller as I already have a robust Template Library, I decided to write my own APP_Controller.php and put it in system folder Code: <?php and Quote:class Examples extends APP_Controller Thes result was Code: Fatal error: Class 'APP_Controller' not found in C:\wamp\www\ci\system\application\controllers\examples.php on line 2
[eluser]Colin Williams[/eluser]
Quote:As i don’t want each unnecessary extra master page template features of MY_Controller as I already have a robust Template Library Makes no sense. And, how do you suppose your APP_Controller file would load? You didn't follow any of CI's naming and file location conventions. Quote:I decided to write my own APP_Controller.php and put it in system folder CI looks in application/libraries for filenames that match those in system/libraries, but prefixed with 'MY_' (a prefix you can change in config if you want) and loads those files automatically. You can keep your APP_Controller in the system folder if you want, but you'll have to include() or require() it manually
[eluser]Mithun[/eluser]
I just got that My APP_Controller is not loading ;-) I Tried the code Code: class MY_Controller extends Controller { and Code: <?php But the below combination, code without MY_Controller works Code: <?php
[eluser]flaky[/eluser]
maybe this is the culprit Code: <?php change it to Code: <?php
[eluser]Mithun[/eluser]
yea that was, just changed to Code: <?php |
Welcome Guest, Not a member yet? Register Sign In |