Welcome Guest, Not a member yet? Register   Sign In
Run another controller's method
#11

[eluser]Edemilson Lima[/eluser]
This is exactly what I was pointing out in my post at:

http://ellislab.com/forums/viewthread/68847/
#12

[eluser]Sam Dark[/eluser]
Sad CI can't run another controller from running one Sad Or just noone knows how Wink
#13

[eluser]Chris Newton[/eluser]
You can call another function in your controller.. why not just do that?
#14

[eluser]jbowman[/eluser]
not promising a timeframe, but since I'll have a use for similar functionality, I'll see what I can come up with. Here's another link http://ellislab.com/forums/viewthread/69467 to another person looking for the same thing. The compare it to the _forward() function in Zend, which is what we want.

To be clear, I'll be trying to come up with a new method for the Controller class which will attempt to route to and run a method from another controller, and return the value returned by that method. If the method runs a view, then the return value would be the final output of that view.

Disclaimer: I'm working on an ldap class to get authentication working for my site first. I have a very time consuming job, and a 6 month old daughter. If you think you can do this quicker than I can in my 2-3 hours to work on personal sites, then by all means, please do Smile
#15

[eluser]jbowman[/eluser]
oh, just to clear up the library vs. controller

Mainly an effort to have things in one place. /blogs would be the controller for blogs. /blogs, blogs/new, /blogs/edit/2, /blogs/latest...

Sometimes I might want to call /blogs/latest from another controller. I don't want to have a BlogsController and BlogsLibrary separated. I don't want blogs all over.

Mainly comes down to the way one person thinks compared to another. I fully see the logic in having a library that will interact with the blogs tabls as well, but, building a library I lose a lot of the MVC standardized coding restraints. Personally, I'm looking to be forced to code a certain way to some extent. Makes it easier for people to follow up on my work, including myself a few years from now.
#16

[eluser]John Fuller[/eluser]
I don't get it.

I have a model for the blog and another for comments (as well as more models for the admin versions of each.) All the controller does is make the calls to all the models needed, loads up the array and spews everything out into the view page. That is all the controller is, a middle man. The real action is going on in the models.

There might be a little bit of overlap between two controllers doing much the same stuff but why be so hardcore about not reusing code? For instance, I have a blog controller and an archive controller. The blog just shows entries and the number of comments. The archives controller shows a single entry, all the comments for that entry and a comment form. The two controllers are similar but not exactly the same.

So in Sam's example, why not do (in my uber pseudocode)

[call model(blog), call model(comments)] => controller => view => collect underpants => ? => profit!
#17

[eluser]jbowman[/eluser]
I think you're exactly right John, this is what I was thinking about last night as I drifted off to sleep. It's not the controller or libraries that matter, it's the models. I just haven't actually begun writing code for this portion of my site yet, so hadn't run into the obvious fact that models is where this logic belongs.
#18

[eluser]Unknown[/eluser]
I am also facing the same problem. Need help
#19

[eluser]jbowman[/eluser]
Wow, this thread is old, got emailed about the reply.

Sorry, I've been using python/django for the past year, as I've been developing on AppEngine. So I'm going to give a high level answer on how to approach this, and hopefully it fits CodeIgniter.

How I handle things like this now in Django, is I create all the functions I need in the Model.

So, I might have a class called Blog

The Blog would have methods like get($count), get_latest($count), etc etc...

Then for the portal view, you might call $Blog->get_latest(10) where as the view would call get.

The idea is your Model is the interface to the data. Your Model includes functions that gets the data as limited as you need it, and preformatted for your controllers to use.

Hope this helps.
#20

[eluser]Thorpe Obazee[/eluser]
[quote author="jbowman" date="1242767657"]Wow, this thread is old, got emailed about the reply.[/quote]

That's one reason I don't subscribe Tongue




Theme © iAndrew 2016 - Forum software by © MyBB