How to serve static pages with Zend Framework
Asked Answered
W

1

6

We currently employ Zend Framework and the MVC pattern on our website. We have large numbers of static pages, which are in random areas of the site. These pages are not simple HTML pages that can bypass ZF altogether... they would participate in the Zend_Layout, etc.

What is the best way to serve these pages without creating a separate action/controller for each random page? Redoing the layout of the pages so that they all fall under a "misc" controller or something is not an option, the pages need to stay where they are in our URL hierarchy for SEO purposes.

Whippet answered 21/4, 2009 at 18:33 Comment(3)
static but random? don't get it? what about serving them as includes from one controler/action?Enroll
They're static in the sense that there is no good reason to have a whole controller and view action associated with them. And there are 100s of pages scattered through the site. Theyd basically be plain html, but I want the layout injected, along with other ZF specific functionality intact.Whippet
I am almost certain he means a static page controller that serves views based on url. Like domain.com/pages/about/us would serve the /views/pages/about/us.html view. I believe most frameworks comes with this out of the box, why does zend make it difficult? Ref : book.cakephp.org/view/958/The-Pages-ControllerVictualage
H
6

If I understand the question properly:

  • You have a bunch of static content you would like to apply your layout to.
  • These pages of static content already have existing urls you don't want to break

Zend actually separates URL from $controller->action(), it just so happens the MVC part of Zend has a default setting to do this. You can still create a "misc" controller which receives any random url, you just need to define some custom routes.

http://framework.zend.com/manual/en/zend.controller.router.html

quoting example Zend Framework site:

$route = new Zend_Controller_Router_Route_Static(
    'login',
    array('controller' => 'auth', 'action' => 'login')
);
$router->addRoute('login', $route);

Above route will match a URL of http://domain.com/login, and dispatch to AuthController::loginAction().

More ambitious examples using pattern matching can be found on the same page.

Hamfurd answered 21/4, 2009 at 23:43 Comment(2)
How does this solve the question? I have a statically generated HTML directory, which is a user guide to the application, and is at the same level as Zend's directories. I cannot get it to show any HTML files under /userguide folderShoshana
If you're still using Zend Framework 1.12, here's an updated link to the router documentation referenced in TK's answer. framework.zend.com/manual/1.12/en/zend.controller.router.htmlBistoury

© 2022 - 2024 — McMap. All rights reserved.