1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Zend Router

Discussion in 'PHP' started by dbsuk, Feb 10, 2011.

  1. #1
    I have been working on a way to have Zend Framework route dynamic page names to my CMS controller, I have done quite a bit of Google searching and cant seem to find anything that does the exact thing I want.

    I think I have a solution, its not exactly what I started out for but it appears to work without affecting Zend's default routes.

    my routes.ini file is as follows.

    
    
    routes.cms.type = "Zend_Controller_Router_Route_Regex"
    routes.cms.route = "^(.*).html"
    routes.cms.defaults.module = "default"
    routes.cms.defaults.controller = "index"
    routes.cms.defaults.action = "index"
    routes.cms.map.1 = "slug"
    
    
    PHP:
    This allows me to enter the URL http://localhost/someCMSpage.html .

    Which routes to my CMS controller.

    In the CMS controller I can do

    
    
    $slug = $this->_request->getParam('slug');
    
    
    PHP:
    $slug would = "someCMSpage", I can then search the page table for WHERE slug = $slug.

    I figured I could also enter something like URL http://localhost/parentPage/someCMSsiblingpage.html and then just trim off anything before the last / (forward slash).

    Though this works, as always with Zend Framework I am skeptical theres probably other ways of doing this.

    Does anyone have any comments on my method or can suggest any improvements / different ways of doing this I would be interested.

    Cheers

    Richard
     
    dbsuk, Feb 10, 2011 IP