Welcome Guest, Not a member yet? Register   Sign In
Controller / function loading twice?
#1

[eluser]mipa[/eluser]
I have a bizarre issue with the following behavior:

Adding parameters to a URI causes the application to load twice, the second time butchering all URI segments after the third one.

The pages use the OB Session library.

Have I funked up some configuration settings somewhere? Or is there some other reason for this behavior? Any insight would be appreciated!
#2

[eluser]coolfactor[/eluser]
Some example code would really be useful.
#3

[eluser]mipa[/eluser]
Yeah, I know, unfortunately, it's "confidential" company stuff.

Regardless, we've been narrowing down the problem. We believe it stems from our unorthodox inclusion of another extension to the Controller class.

Situation is like this: we have multiple applications sitting on the framework. Two of our applications share the same extended controller functions, which we added to the "MY_Controller.php" file. However, one of the applications still needs to extend the Controller class, so we created another class Base_controller. So, our controllers extend Base_controller which in turn extends MY_Controller. We're currently trying to look into a better way to manage this situation.
#4

[eluser]coolfactor[/eluser]
When using a MY_Controller subclass, the Controller class is still loaded. You don't need to extend from MY_Controller all the time.

... extend from MY_Controller:
Code:
class Products extends MY_Controller
{

}

... extend from just Controller:
Code:
class Customers extends Controller
{

}
#5

[eluser]mipa[/eluser]
Thanks, however the issue in this case is that we WANT the functionality in MY_Controller PLUS the functionality in our more-customized Base_controller.
#6

[eluser]coolfactor[/eluser]
[quote author="mipa" date="1186661565"]Thanks, however the issue in this case is that we WANT the functionality in MY_Controller PLUS the functionality in our more-customized Base_controller.[/quote]

Well then you're doing it the correct way. However, don't be afraid of putting a lot of methods into MY_Controller. PHP is very fast at loading large files. It takes much longer to load two controller files than it does to load one larger one.

Alternatively, you might consider putting some of the shared functionality into libraries.
#7

[eluser]mipa[/eluser]
If we're doing it the right way, why does it load the page twice? I think we must have introduced some sort of conflict into the framework. BTW, we used "include()" to include the MY_Controller.php file in the Base_controller.php file. Is there a better, more highly recommended way to do this?
#8

[eluser]coolfactor[/eluser]
Using include() or include_once() is the correct way to include the MY_Controller.php file.

How many times does a page request use $this->load->view()? Do you use that to load partial views into variables, or do you just call it once?
#9

[eluser]mipa[/eluser]
Multiple times -- we're loading partial views into a main template view.
#10

[eluser]coolfactor[/eluser]
Can you disable the OB_Session library to see if the double loading goes away? I suspect it has something to do with the output buffering.




Theme © iAndrew 2016 - Forum software by © MyBB