Welcome Guest, Not a member yet? Register   Sign In
Calling a controller from another controller
#1

[eluser]Mr Lazy[/eluser]
Hi,

In other languages and frameworks, I have called another controller from within a controller. How do you do this in CI? I have scanned the forums, and I have found nothing...

Thanks,
L
#2

[eluser]Yash[/eluser]
Search Lazy

there is a library to achieve this aim.I'm forgetting name.contributed by some user.

search library section
#3

[eluser]Mr Lazy[/eluser]
er.. thanks for the help.

I managed to do what I was trying to achieve using redirect in the URL helper.

L.
#4

[eluser]Colin Williams[/eluser]
Controllers in CI are mapped directly to the URL. It's not exactly meant for Controllers to serve other Controllers. However, you can use Modular Extensions or Wick, two contributed libraries, if you feel you must. If you just need to invoke a different page, using redirect will work, and if you need to communicate data to the new request, either pass it in the URL or store in a flashdata session variable.
#5

[eluser]Mr Lazy[/eluser]
I think this comes down to how I am used to using a MVC structure with a different framework. It was common to serve/call other controllers, but not via a URI. You just told the framework which controller to use in the calling controller. I think redirect is the CI equivalent, but I am surprised it is not built in. But, as long as it works, that's the important thing... and it seems to.

Thanks,
L
#6

[eluser]xwero[/eluser]
What you are describing seems more like routing than displaying one controllers output as a part of another. The latter is the most wanted use when calling a controller method in another controller.
#7

[eluser]wiredesignz[/eluser]
[quote author="Colin Williams" date="1223649718"]Controllers in CI are mapped directly to the URL. It's not exactly meant for Controllers to serve other Controllers. However, you can use Modular Extensions or Wick, two contributed libraries, if you feel you must.[/quote]


True MVC is exactly controller to controller communication. Anything else is a mistaken understanding of MVC.
#8

[eluser]Randy Casburn[/eluser]
[quote author="wiredesignz" date="1223656677"]
True MVC is exactly controller to controller communication. Anything else is a mistaken understanding of MVC.[/quote]

Oh boy here we go again!

OK wired if you can make this statement, you can point to the SINGLE definitive definition that is AGREED upon by the computer science or software engineering societies of what constitutes THE MVC design pattern.

Provide the one link please.

Randy
#9

[eluser]Randy Casburn[/eluser]
As an example of what I mean:

In JAVA Swing, the MVC Design Pattern is called a Usage Model. It has been modified to the extent that the Controller and Model are somewhat mushed together. Really what has happened is the Controller has been replaced completely by a single Observer pattern that arbitrates the event management issues normally handled by a Controller.

In JAVA Struts on the other hand, there are actually two (2) interpretations of the MVC design pattern. One of them uses a single controller and the other uses two controllers working in conjunction with each other.

The most popular PHP frameworks oriented around the MVC design pattern commonly refer to a 'front controller' while instructing the developers to build the MVC Controller for the design pattern. This implies more than one controller.

In CI, by definition, codeigniter.php is a controller since it is responding the input from the user interface (the URI) and making choices (routes, hooks, etc.) based upon that input. We build secondary controllers based upon our needs.

All of this is academic and pointless since it doesn't help the OP -- Colin's attempt was meant to shed light on how CI accomplishes things. There is no one agreed definition of what the MVC design pattern means or how it is implemented.

There is no "true MVC".

If the OP wants to expose the framework he/she was making comparison to then we would be better prepared to make comparisons and point out the differences in implementations.

Randy
#10

[eluser]Colin Williams[/eluser]
Just to be clear, I'm not claiming controllers serving other controllers is bad MVC. It's just not CodeIgniter MVC.

Quote:Colin’s attempt was meant to shed light on how CI accomplishes things

See. Randy got the point.




Theme © iAndrew 2016 - Forum software by © MyBB