Welcome Guest, Not a member yet? Register   Sign In
another controller within a controller?
#5

[eluser]drophere[/eluser]
Just bump:

After reading both Wiki on Modular CI and ME closely I thought it'd be too much for what I want.

All I wanted to have is to have the same function applied to each controller, just without having to rewrite this main 'user' controller in every single controller.
Of course, there's some URI fun involved in this matter but anyway I gave it a try.. :o


I made a library extending Controller, so its MY_Controller. I converted the 'user' controller into this library: pretty much the same except for the class name and the constructor parent:: thing..
But then I need to receive an input, which is the segment 2.

I tried to solve it using /application/config/routes.php, making something like this: $route['user/(:any)/(:any)'] = '$2';

so any url starting with "user" followed by any "username (the first (:any) = $1" will be routed to the controller, which is in the third segment.
In real world the URI should look like http://codeigniter/index.php/user/drophere/blog.
In this case, the $2 will be 'blog', routed to "blog" controller so natural way...

While doing this, the MY_Controller library, which always comes before any of the controllers as they just extend this library, will fetch some user information I desired with the second segment, $1.

This way, whatever controller comes after as long as I start my url with "user", they will be able to use the user information I was fetched in the MY_Controller library.

So I thought It'd work.. because the index page of blog controller showed up.

However I cannot use any methods on it. How sad?!

Whatever I put in the URI as method, so it is to be http://codeigniter/index.php/user/drophere/blog/METHOD, it will just show 404 page even if the blog controller DOES have the method.
I presume this is something that has to do with CI's internal routing function.. I hacked into the core and actually got the point where the 404 page is shown and tried to look up... hmm... no I'm not this good yet.
However I got this vibe: CI is trying to find the method from somewhere different.

As soon as I put another (:any) to the routes.php and trying to get to the method it actually works, but the index() is broken..........WT$#^#^@%?
I'm totally confused.

So-

I will probably just look for the ME or the Modular CI. Even if what I want seems to fit extending the native library better, just because I got this crazy URI thing going around.. o.O


Messages In This Thread
another controller within a controller? - by El Forum - 08-29-2010, 04:54 AM
another controller within a controller? - by El Forum - 08-29-2010, 05:58 AM
another controller within a controller? - by El Forum - 08-29-2010, 06:09 AM
another controller within a controller? - by El Forum - 08-29-2010, 06:49 AM
another controller within a controller? - by El Forum - 08-29-2010, 08:57 AM
another controller within a controller? - by El Forum - 08-29-2010, 01:20 PM
another controller within a controller? - by El Forum - 08-29-2010, 05:06 PM
another controller within a controller? - by El Forum - 08-29-2010, 07:30 PM
another controller within a controller? - by El Forum - 08-29-2010, 09:41 PM
another controller within a controller? - by El Forum - 08-30-2010, 07:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB