-- 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
)
);
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/