Welcome Guest, Not a member yet? Register   Sign In
extending base controller
#11

[eluser]vecima[/eluser]
oh. well if that's the only difference, I'll leave it where it is. It'd be more work to move the file and delete the line of code than to do nothing.
#12

[eluser]Aken[/eluser]
[quote author="vecima" date="1253050737"]sorry for dragging up this old post, but is there any reason why your base controller needs to be in the application/libraries folder?

I have a Base_Controller that extends Controller, and it's in my application/controllers folder. all of my other controllers extend Base_Controller and it works fine for me.

am I doing something wrong?[/quote]
The original Controller class is a default CodeIgniter library, just like other classes like Form Validation, Database, Image Manipulation, etc. If you want to replace or extend one of these, CodeIgniter automatically looks in your "applications/libraries" folder for a class name with the "MY_" (or other specified) extension in front of it.

Also by putting your extended Controller class into the controllers folder, the scheme will look exactly like a standard controller (IE "class Extended_controller extends Controller"), and possibly may be accessible via normal URI strings.

It's really just best practice to leave it in the Libraries folder in the future. Honestly I'd make the time to change out the code again also. Most text editors have a find/replace option which would make the time for each file very limited.
#13

[eluser]vecima[/eluser]
It's not much of a change really, it's just that I still wasn't clear as to what the difference is. Thank you for specifying about the URI string access... people accessing my site with "domain.com/Base_Controller/" isn't very aesthetically pleasing I suppose.

I don't personally want to call it MY_Controller (as I just think that's a dumb name) but if I change that prefix and specify my own in the config, might I have to make that change each time I update to a new version of CI?

If I put it in libraries/Base_Controller.php forsaking the "MY_" and not specifying my own prefix I take it CI doesn't auto load it... so does that mean it'll need the "require_once"?
#14

[eluser]jedd[/eluser]
[quote author="vecima" date="1253169946"]
I don't personally want to call it MY_Controller (as I just think that's a dumb name)
[/quote]

application/config/config.php : $config['subclass_prefix'] = 'MY_';

Quote: but if I change that prefix and specify my own in the config, might I have to make that change each time I update to a new version of CI?

It's in the user configuration file in the user's configuration directory - so no.
#15

[eluser]vecima[/eluser]
so files in /application/config/ never ever ever forever never need to change with new versions of CI?
#16

[eluser]jedd[/eluser]
Are you genuinely asking me to predict the future?

How sweet.

I can say that the stuff under application/... is treated as being owned by the developer - as opposed to the stuff under system/... which is .. well .. less so.

Two things worth observing here.

First, once you install a live site, you tend to not need to go and upgrade the CI component later - it's rare indeed for there to be a security alert relating to their codebase.

Secondly, if you do want to upgrade, there's the handy 'upgrade from x to y' instruction page that you can quickly glance over to determine if it's going to break any of your changes.

Having said all that - I can also say with a certain degree of quiet confidence that no, your changes to config.php will never be munged by an upgrade.
#17

[eluser]vecima[/eluser]
sold.

thanks!




Theme © iAndrew 2016 - Forum software by © MyBB