Basic Zend Controller Route
Here is the basic sample that will change the Zend Framework default controller router.
Basically you need to follow the /controller/action/define-url/define-url2 and so on, let put in the actual url, example you have category and category name(category name is dynamic), and you want to view the list of products that belong to category name, the url should be /category/view/categoryname/beauty-product. Okay, we know that is bad in SEO rule, of course we need to simplify it, and should be /category/beauty-product.
// application/bootstrap.php
protected function _initRouterCategory()
{
$ctrl = Zend_Controller_Front::getInstance();
$router = $ctrl->getRouter(); // returns a rewrite router by default
$route = new Zend_Controller_Router_Route(
'category/:slug',
array(
'categoryname' => 'action',
'controller' => 'category',
'action' => 'view'
)
);
$router->addRoute('category', $route);
}
Then browse the category then you will see
This post is tagged: zend framework, zend framework tutorial
One Response to “Basic Zend Controller Route”
Leave a Reply

I don’t understand! honestly…