Zend framework, mapping urls in the database

Having set up the application and got it to serve a page from the database, I need to make sure that it was getting the content I wanted.

I wanted to have something like http://localhost/my_title find the content from the url field with value my_title

I added this to my Bootstrap.php

protected function _initRoutes() {
        $frontController = Zend_Controller_Front::getInstance();
        $router = $frontController->getRouter();

        $route = new Zend_Controller_Router_Route_Regex(
            '(\w*)',
            array('controller' => 'content',
                'action' => 'index' ),
            array(1 => 'url')
        );


        try{
           $router->addRoute('content', $route);
        }catch(Exception $e) {
            print($e->getTraceAsString());
        }

    }

This mapped to the ContentController class with the following code

public function indexAction()
    {
        // action body
        $content_mapper = new Application_Model_ContentMapper();

        $url = $this->getRequest()->getParam('url');
        $content = new Application_Model_Content();
        $content_mapper->findByUrl($url, $content);
        $this->view->content = $content;

    }

Comments are closed.