• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loading Controller from another Controller

#1
[eluser]drakeonfire[/eluser]
Hello,

Title kinda says what I need to do.

For example I have controller "main", which also has a routing function in (to determine where certain things need to go), and it may need to go to product or blog controller etc, how can I do this?

If I can make one request - please do not try and question the logic behind the routing function, as there is good reasoning for it, I can assure you.

Thank you!

#2
[eluser]InsiteFX[/eluser]
Phil Sturgeon's - CodeIgniter Base Classes: Keeping it DRY

#3
[eluser]drakeonfire[/eluser]
Hello,

Thanks for the reply.

I checked it out, but I'm not sure if that's what I was aiming for. For example I don't need to share functions as such, I just need to do something like this:

I have a routing function, (In the 'Main' controller), and say, from it's logic it determines that the page (method) the person was trying to access is in the 'Category' controller. How can I activate this method? as once it's activated I wouldn't need to do anything more, as that would be handled by the method in the 'Category' controller.

Any ideas? Or should I just make it so it includes the controller then activiates it manually?

Thanks

#4
[eluser]CroNiX[/eluser]
The route regex (in /application/config/routes.php) should be able to determine that and steer the request to the appropriate controller based on the detected route. Either that or what you are calling a "category controller" should really be a library.

#5
[eluser]drakeonfire[/eluser]
Hmm, the problem is, the reason the config routes can't handle it is I am interacting with tables to determine whether the url is valid, as for example, I know some pages exist (e.g Home, Login etc), but I don't know whether certain things like this_page exist, about etc, as it's using a CMS that allows the admin to add pages, which are using uri's defined by them (e.g. they may call it this_is_a_page .. but that's not going to have a method in a specific controller...

So as I have multiple things like this, as it also has it's own short code system (e.g. a85axn goes to a certain blog page), I didn't think it would be a good idea to do it in the config route. As theres few controllers it could end up needing to be in ...

Any ideas Sad?

#6
[eluser]CroNiX[/eluser]
I have a similar setup on several of my sites. I have routes defined for all of my regular controllers, and a catch all route last. If the route isn't picked up by one of the defined routes (which aren't dynamic) it goes to the last catch-all route, where it loads a controller which checks for that route in the database (via a slug). If it exists it serves the (dynamic) page, if not it 404s.

#7
[eluser]drakeonfire[/eluser]
Hello,

Thanks for the info! While reading that I realised I was going about this in a rather odd way. I just realised that if I use your method, once it determines the page type, it can go to a method in that controller to set it up.

Thanks for the help.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.