I don't exactly get what you're up to but i think we have a slight confusion
in here.
A route is generally meant as a pattern against which a given URI is matched
to _before_ any FooController.php is called. In a route, you define how the
given URI-request is to be evaluated, i.e. if a part of the given URI should
be interpreted as an :ELEPHANT_ID or a :GIRAFFE_NECK_LENGTH. When you define
a new route in IndexController::showAction() it is simply too late; the
request has already been evaluated (probably against the standard pattern
"[/MODULE]/CONTROLLER/ACTION" that is why he tries to call the non-existing
ShowController.php).
I'm not sure, but i guess you are up to a forward/redirect! Just use either
Zend_Controller_Action::_redirect() which is a hard redirect, i.e. the
server orders the client's browser to call the new URI that results in a
completely new request.
The second method you could use is Zend_Controller_Action::_forward() which
is a rather "soft" redirect, i.e. it just calls the new controller-action
you give _forward() as param.
If i'm wrong guessing and you don't want to redirect, define your routes
pretty much earlier, e.g. in a Bootstrap.php.
Ciao Nico
On Fri, Jan 7, 2011 at 7:02 PM, Erdal YAZICIOGLU <erdal.yazicioglu@gmail.com
> wrote:
> Thanks Juan Pablo
>
> But even that does not help. I changed a litle bit the code. But I still
> have the invalid controller (show) message while it is an action in
> IndexController
>
> front = Zend_Controller_Front::getInstance();
> $router = $front->getRouter();
> $route = new Zend_Controller_Router_Route(
> 'show/:articleID',
> array(
> 'controller'=>'index',
> 'action'=>'show'));
> $router->addRoute('show', $route);
>
> 2011/1/7 Juan Pablo Marroni <jmarroni@gmail.com>
>
> > Hello Erdal, I think that your code have a little mistake, I use
> Zend_Route
> > and I changing the code in red:
> >
> >
> > public function indexAction()
> > {
> > $articles = new Application_Model_Articles();
> > $this->view->articles = $articles->listArticles();
> > $front = Zend_Controller_Front::
> > getInstance();
> > $router = $front->getRouter();
> > $router->addRoute('show',
> > new Zend_Controller_Router_Route('show/:articleId', array(
> > 'controller' => 'index',
> > 'action' => 'show'
> > ))
> > );
> >
> > :articleId --> This a varible that you receive whit
> > _getParameter("articleId") and containt the value of the id.
> >
> > I hope that this line help you.
> > Best Regards Juan Pablo.
> >
> >
> > 2011/1/7 Erdal YAZICIOGLU <erdal.yazicioglu@gmail.com>
> >
> > Hello all
> >>
> >> I am trying to route from http://localhost/index/show/articleID/1 to
> >> http://localhost/show/articleID/1.
> >>
> >> application/Controllers/IndexController
> >>
> >> public function indexAction()
> >> {
> >> $articles = new Application_Model_Articles();
> >> $this->view->articles = $articles->listArticles();
> >> $front = Zend_Controller_Front::getInstance();
> >> $router = $front->getRouter();
> >> $router->addRoute('show',
> >> new Zend_Controller_Router_Route('show/*', array(
> >> 'controller' => 'index',
> >> 'action' => 'show'
> >> ))
> >> );
> >>
> >> I call this in view as follow
> >> index.phtml
> >> <a href="<?php echo $this->url(array('articleID' =>
> $articles->articleID),
> >> 'show') ?>">Show</a>
> >>
> >> But everytime it tries to route me to ShowController which does not
> exist.
> >> As I understand it suppose to route to showaction. Is there anything I
> am
> >> missing?
> >>
> >> Best Regards
> >>
> >
> >
>
没有评论:
发表评论