I'm pretty new to Zend (read the documents concerning routers and controllers).

My StaticController and IndexController :

class StaticController extends Zend_Controller_Action
{
    public function displayAction()
    {
        $page = $this->getRequest()->getParam('filename');
        $this->render($page);
    }
}

class IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {
        $albums = new Application_Model_DbTable_Albums();
        $this->view->albums = $albums->fetchAll();
    }
    public function registerAction()
    {
        ...
    }
}

application.ini :

resources.router.routes.staticpage.route = /:filename
resources.router.routes.staticpage.defaults.controller = static
resources.router.routes.staticpage.defaults.action = display

My static content urls are : site.com/faq site.com/privacy ...

These work, however others, such as site.com/register uses the StaticController rather than the IndexController, I can't say that I suprised by this behavior.

These static pages (about us, terms and cond...) need to be included in the zend logic for .po translation.

I can think of many diffrent ways to achieve this outside the Zend framework, but would really like to do it the proper zend way.

How can I distinguish static and dynamic content, and still keep pretty urls?

Any help would be much appreciated !

有帮助吗?

解决方案

You could do it this way :

resources.router.routes.staticpages.route = "/:filename"
resources.router.routes.staticpages.defaults.controller = static
resources.router.routes.staticpages.defaults.action = display
resources.router.routes.staticpages.reqs.filename="(list|of|static|pages)"

If you don't know what 'reqs' is, it's very simple. For each param specified in 'reqs' you specify the regexp it should match in order to use this route.

But I personally would use an action per static page instead of a param in a single action, which would require this route :

resources.router.routes.staticpages.route = "/:action"
resources.router.routes.staticpages.defaults.controller = static
resources.router.routes.staticpages.reqs.action="(list|of|static|pages)"

It's planning that you may one day require different logic for rendering some your static pages

其他提示

You should consider using a prefix for static content so the router knows that you are trying to pull static content and not trying to reference an action in the IndexController.

resources.router.routes.staticpage.route = /static/:filename
resources.router.routes.staticpage.defaults.controller = static
resources.router.routes.staticpage.defaults.action = display
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top