1

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 !

Charles
  • 50,943
  • 13
  • 104
  • 142
Sparkup
  • 3,686
  • 2
  • 36
  • 50
  • I'm not quite sure I understand the question. If you go to site.com/faq that should be loading the indexAction of the FaqController class. None of your example URL's should be going to the index OR static controllers. – CashIsClay Sep 23 '11 at 19:49
  • I've added the application.ini. How can I distinguish static and dynamic content, and still keep pretty urls? – – Sparkup Sep 23 '11 at 20:02
  • How come you don't just create a FaqController and a PrivacyController that do nothing but render a view? e.g. in FaqController `public function indexAction() { /* show view */ }` – drew010 Sep 23 '11 at 22:27
  • 1
    @drew010 : a controller for each single static page ? really ? – Frederik Eychenié Sep 23 '11 at 23:14
  • Yes becomes a bit much if he has a lot of static pages, but it can simplify things if one of those static pages has to grow into something multi-page such as a faq section. – drew010 Sep 23 '11 at 23:20

2 Answers2

1

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

Frederik Eychenié
  • 1,253
  • 7
  • 8
  • Thank you for this. Does the first method have any impact on reducing the overhead (compared to second)? – Sparkup Sep 24 '11 at 13:19
  • On the performance level there is no real difference, but i find the second more readable and maintainable. It's up to your own preference – Frederik Eychenié Sep 24 '11 at 13:29
0

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
Christopher Manning
  • 4,527
  • 2
  • 27
  • 36