Welcome Guest, Not a member yet? Register   Sign In
Do not load MY_Controller, although it exists
#1

[eluser]Ki[/eluser]
Hi,
It seems to me that MY_Controller is loaded automatically, regardless of whether I extend it or extend the controller:
Code:
class Help extends MY_Controller{
end
Code:
class Help extends Controller{

Both load MY_Controller. Is there a way to bypass it, because there are quite a few db queries in MY_Controller that may not be required for sections of the website, such as help etc, so I want to avoid unnecessary load
#2

[eluser]InsiteFX[/eluser]
You can not have two classes with the same names its a conflict.
Change the name of one of your classes.

Enjoy
InsiteFX
#3

[eluser]Ki[/eluser]
Its one class loading either MY_Controller or Controller.
#4

[eluser]InsiteFX[/eluser]
As I stated above!

You can have one or the other not both
even if there in one class file.

Also all your database queries etc. Should be in a model.

Load the model then decide what queries you need in your
Controllers.

Enjoy
InsiteFX
#5

[eluser]Ki[/eluser]
I do not think I clearly explained myself.
I have one controller - lets call it Help. If I extend MY_Controller, everything is ok. If I change that controller to extend Controller I get all stuff that is done in MY_Controller, models loaded, functions called etc... Is that normal?

Ki
#6

[eluser]danmontgomery[/eluser]
The class is loaded, yes... Autoload wasn't supported until PHP5, so it's not currently included in CI... If the file exists with the correct prefix, it's loaded... If you think about extending helpers, libraries, etc, you are still loading the class normally:

Code:
$this->load->library('form_validation');

If an extension of form_validation exists, it is automatically loaded.

Extending the Controller class is a little different, in that you are extending the class definition for each controller... So, the MY_Controller class is loaded, but if you're extending the Controller class, you would still only have access to those class methods and members.
#7

[eluser]InsiteFX[/eluser]
Is MY_Controller in your application/libraries folder?

Also are you changing your Constructor to My_Controller
or Controller?

parent::Controller();
or
parent::MY_Controller

Enjoy
InsiteFX
#8

[eluser]cahva[/eluser]
Use technique that is explained here:
http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY

I dont use MY_Controller at all anymore. I just add that autoload function to config.php and add my base controllers to libraries folder. Plus you can use 3rd party non-ci classes easily also.

So with this its easy to add for example Front_controller, Backend_controller, Auth_controller etc. that you can extend in your controllers according what you want.
#9

[eluser]Ki[/eluser]
Ironically enough, my approach is very similar to what Phil explains.
But let use his example. In his MY_Controller version he calls a session method as such:
$user_id = $this->session->userdata('user_id');
This is available to all controllers that extend MY_Controller. My question is that if someone has a portion of site that is purely static, such as help/about_us, Is there a way I can load just the basic Controller and skip the loading of MY_Controller and also skip "$user_id = $this->session->userdata('user_id');" part to speed up the process?

Or am I completely not understanding what you guys are telling me?
#10

[eluser]n0xie[/eluser]
If you don't extend from MY_Controller, it doesn't load MY_Controller. So if you have a controller Help just don't extend it from controller and you should be good.




Theme © iAndrew 2016 - Forum software by © MyBB