Hector,

I appreciate the help.

I decided to use this method with the slight change of deciding to
define the static pages with a .html extension.  Continuing with the
example I've been using, I'll access the non-controller pages using,
for example, mysite.com/About-Us.html, mysite.com/Contact-Info.html,
etc.

Using this predefined schema will allow me to have the static pages
without having to create a custom route for every module/controller
that I might end up defining.

I've modified my application.ini file as you indicated with the
exception of the regular expression you used.  I've instead narrowed
the scope to only route *.html to my Page controller.

Here is pertinent line from my application.ini file:
resources.router.routes.page.route = "(.*\.html)"

I can have my static files, and define any controllers I need without
having to define a custom route for everyone.

Thanks again,
Adam


On Wed, Jan 25, 2012 at 11:55 AM, Hector Virgen <[email protected]> wrote:
> On Wed, Jan 25, 2012 at 7:20 AM, Adam Dear <[email protected]> wrote:
>>
>> Is the proper way to create a custom route that routes every request
>> to my default controller, and then define routes that send requests to
>> few actual controllers that will exist or is there a mechanism that I
>> could use in a front controller plugin that would be more appropriate?
>>
>
> I prefer the idea of creating a custom route and mapping it to a common
> controller/action that can load any arbitrary page that exists in the
> database. For example, you can add this route to your config:
>
> resources.router.routes.page.type = "Zend_Controller_Router_Route_Regex"
> resources.router.routes.page.route = "(.*)"
> resources.router.routes.page.defaults.controller = "page"
> resources.router.routes.page.defaults.action = "view"
> resources.router.routes.page.map.1 = "slug"
> resources.router.routes.page.reverse = "%s"
>
> This would catch *all* requests and route them to the "page" controller's
> "view" action. Within that action, you can look in to the database for the
> page that matches the "slug" parameter:
>
> $slug = $this->_request->getParam('slug');
>
> If you visit /about, then $slug will be "about". If you visit
> /foo/bar/derp.html, then $slug will be "foo/bar/derp.html".
>
> This means you'd have one controller, one action, and not need to copy/paste
> the same code in multiple controllers. You can also create new pages by just
> adding a new row to the database.
>
> In the case where a page cannot be loaded from the database, throwing an
> exception from within the action would trigger your error page (error
> controller, error action).
>
> The drawback to this approach is that you'll lose the built-in default
> routing that maps the URL to module, controller, and action. You may want to
> set up new routes to handle specific controllers. For example, if you wanted
> to expose the other action methods in your "page" controller, you could add
> a route like this:
>
> resources.router.routes.page.type = "Zend_Controller_Router_Route"
> resources.router.routes.page.route = "page/:action/*"
> resources.router.routes.page.defaults.controller = "page"
>
> You would have to repeat this for each controller you want to expose.
>
> I hope this helps!
>
> --
> Hector Virgen
> http://www.virgentech.com
> Circle me on Google+ https://plus.google.com/101544567700763078999/
>
>
>
>

--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to