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

[eluser]Phil Sturgeon[/eluser]
[quote author="Sam Dark" date="1203118486"]Sorry for not replying for a while.

jbowman is right: I'm trying to implement potal-like View library so it will be able to handle something like this:

Code:
<html>
  ...
  <body>
    <div class="sidemenu">
      <h2>Recent posts</h2>
      &lt;?=call_controller('blog', 'recent', array('count' => 10))?&gt;
      <h2>Recent comments</h2>
      &lt;?=call_controller('comments', 'recent', array('count' => 10))?&gt;
    </div>
    <div class="content">
      &lt;?=$content?&gt;
    </div>
  &lt;/body&gt;
&lt;/html&gt;

Calling blog controller's recent action with an array of options and returning output.

Why I don't want to implement those recent posts/blog as library?

1. I don't want to write and load library for each of these blocks.
2. I want to use controller's output on it's own page also.[/quote]

What you are describing here is the use of a model. This looks like you are just pulling and returning some data basedo na few parameters. That is what a model does. A controller is simply for working out which models, libraries and views to load based on a URL.

But if you must be awkward and do it your way, simply use a include() and call the class.

Example:

Code:
&lt;?php
class Blogs extends Controller {

function some_page() {
  include('./other_controller.php')

  $other_controller = Other_controller();
  $values = $other_controller->some_method();
}

}
?&gt;

I almost feel dirty for showing you that. There is NO case in which you need to do this. If you think you do, you are doing it wrong. Guaranteed.


Messages In This Thread
Run another controller's method - by El Forum - 02-13-2008, 03:50 AM
Run another controller's method - by El Forum - 02-13-2008, 06:01 AM
Run another controller's method - by El Forum - 02-13-2008, 07:00 AM
Run another controller's method - by El Forum - 02-13-2008, 07:03 AM
Run another controller's method - by El Forum - 02-13-2008, 10:50 AM
Run another controller's method - by El Forum - 02-13-2008, 11:02 AM
Run another controller's method - by El Forum - 02-13-2008, 10:18 PM
Run another controller's method - by El Forum - 02-13-2008, 11:23 PM
Run another controller's method - by El Forum - 02-15-2008, 11:34 AM
Run another controller's method - by El Forum - 02-15-2008, 11:51 AM
Run another controller's method - by El Forum - 02-15-2008, 02:53 PM
Run another controller's method - by El Forum - 02-15-2008, 03:01 PM
Run another controller's method - by El Forum - 02-15-2008, 06:42 PM
Run another controller's method - by El Forum - 02-15-2008, 08:30 PM
Run another controller's method - by El Forum - 02-15-2008, 08:34 PM
Run another controller's method - by El Forum - 02-15-2008, 10:24 PM
Run another controller's method - by El Forum - 02-16-2008, 06:44 AM
Run another controller's method - by El Forum - 05-19-2009, 09:49 AM
Run another controller's method - by El Forum - 05-19-2009, 10:14 AM
Run another controller's method - by El Forum - 05-19-2009, 07:28 PM
Run another controller's method - by El Forum - 05-20-2009, 02:09 AM
Run another controller's method - by El Forum - 05-20-2009, 02:10 AM
Run another controller's method - by El Forum - 05-20-2009, 02:35 AM
Run another controller's method - by El Forum - 05-20-2009, 09:19 AM
Run another controller's method - by El Forum - 07-03-2010, 06:51 PM
Run another controller's method - by El Forum - 07-04-2010, 08:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB