----- Original Message -----
From: "Matthew Weier O'Phinney" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, November 09, 2006 8:45 PM
Subject: Re: [fw-general] Using multiple controllers
-- Sylvain Philip <[EMAIL PROTECTED]> wrote
(on Thursday, 09 November 2006, 08:25 PM +0100):
----- Original Message -----
From: "Matthew Weier O'Phinney" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, November 09, 2006 7:18 PM
Subject: Re: [fw-general] Using multiple controllers
> you now have the following URL routes:
>
> /foo
> /foo/bar
> /bar
> /bar/foo
> /bar/baz
>
> You can also forward to methods in other controllers:
>
> class FooController extends Zend_Action_Controller
> {
> public function barAction()
> {
> // do some processing
> $this-> _forward('bar', 'foo');
> }
> }
>
> What this does is instruct the front controller that it needs to execute
> BarController::fooAction() after processing the current action.
I'm ok about this simple exemple, but concretly, in more complex situation,
there is a probleme;
Imagine you want to construct a back-office and access by this way: /admin
So if we want administrate a news module, for instance, and construct your
url like this: /admin/news/update/id/1/
params currenty are:
array(
'controller'=> admin,
'action' => 'news',
'update'=> 'id',
'1'=> null
)
But, in fact, we would like :
array(
'controller'=> admin,
'action' => 'news',
'id'=> 1,
)
To solve this problem, I found this solution in the url :
/admin/news_update/id/1
Then I use the __call method in AdminController to parse the
"controller_action" and forward to to the NewsController as bellow:
You actually probably want to use the RewriteRouter in a situation like
this, instead of jumping through the hoops you detail. I'd suggest the
following:
// news controller for basic viewing, searching, navigating of news
class NewsController extends Zend_Action_Controller {}
// NewsAdmin controller extends news controller to add admin actions
class NewsAdminController extends NewsController {}
// Create routes for admin:
$route->add(
new Zend_Controller_Router_Route(
'news-admin',
'/admin/news/:action/id/:id',
array('controller' => 'news-admin') // gets deconstructed to
NewsAdmin by router
)
);
Yes, it's a good idea to extend NewsController with NewsAdminController but it doesn't solve the
problem about AdminController (it have to instantiate other objects to the View ). The ideal should
be to extend two classes but it's an impossible PHP construction:
ActionController
^ ^
/ \
/ \
AdminController NewsController
^ ^
\ /
\ /
AdminNewsController
In fact, I'm construct a CMS on Zend framework with back-office and front-office and currentlly I
have this design:
Index.php -> set the main template view (for back and front-office)
IndexController ->set the path to the front include templates and instantiante some model parts ,
then __call the sub-controller () wich instantiate the rest of the model
adminController ->set the path to the back include templates then do the same
IndexController things
Index.php -> render the view.
I don't know what's the best way to make a CMS on Zend framework...