Welcome Guest, Not a member yet? Register   Sign In
Extending the controller multiple times
#1

[eluser]dejavu[/eluser]
I've created a Crud_controller extension of the MY_controller extension. I want to extend it once more to actually reuse CRUD, but am unsure of the proper way to include the file, especially if I want my code to be reusable.

I can simply:
Code:
require_once('application/controllers/crud_controller.php');

But is there a better way to do it that will let it work with any CI install?
#2

[eluser]jedd[/eluser]
What functions are in your CRUD controller?
#3

[eluser]dejavu[/eluser]
Create (add), Read (display), Update, Delete. Also a config function to help create an array of labels, ids, rules, names, etc for input variables.
#4

[eluser]jedd[/eluser]
[quote author="dejavu" date="1274900620"]
Create (add), Read (display), Update, Delete.
[/quote]

I was alluding to the question of whether these functions are doing database work - in which case they should not exist in the controller(s) at all.

Quote:Also a config function to help create an array of labels, ids, rules, names, etc for input variables.

These sound like they could be helpers.
#5

[eluser]dejavu[/eluser]
[quote author="jedd" date="1274910574"][quote author="dejavu" date="1274900620"]
Create (add), Read (display), Update, Delete.
[/quote]

I was alluding to the question of whether these functions are doing database work - in which case they should not exist in the controller(s) at all.
[/quote]
The model does the actual CRUD, the controller handles the views for CRUD.

Quote:
Quote:Also a config function to help create an array of labels, ids, rules, names, etc for input variables.

These sound like they could be helpers.
Not the way I'm doing this. It displays an array to be cut and pasted into the model to set defaults.

Anyway, this doesn't help with the original question - how to extend the controller multiple times?
#6

[eluser]jedd[/eluser]
[quote author="dejavu" date="1274911729"]
Anyway, this doesn't help with the original question - how to extend the controller multiple times?
[/quote]

I believe your original question was flawed, hence I was searching for better solutions. When the only tool you have is a hammer, all your problems look like nails. Etc.

Quote:Not the way I'm doing this. It displays an array to be cut and pasted into the model to set defaults.

This sounds sub-optimal.


One way to do multiple extensions of the Controller class is to put multiple classes in the MY_Controller file. This is usually the option most people seem to adopt (judging from previous threads on the subject) consequently I'd suggest this may be the first thing you should try.




Theme © iAndrew 2016 - Forum software by © MyBB