Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework Rerouting for Friendly SEO URL?

I don't even understand where to start using the documentation and it's instructions. A little dumbfounded.

I have the URL : http://www.site.com/test/view/?aid=155 right now.

I want it to show up as http://www.site.com/test/155 (Using controller "test" and action "view" with parameter aid as 155)

and for future learning experiences, how would I do http://www.site.com/madeupname/155

Where would I start? What file?

What do I put in it?

Please and thank you!!!!!

like image 608
Darius Avatar asked Dec 10 '25 19:12

Darius


1 Answers

It's not that hard to do, especially if you use an .ini file for your routes. Create a routes.ini file inside of your /site/application/configs folder.

For example :

[production]
routes.home.route = /home/
routes.home.defaults.controller     = index
routes.home.defaults.action         = index

routes.login.route = /login/:username/:password
routes.login.defaults.controller    = index
routes.login.defaults.action        = login
routes.login.defaults.username      = username
routes.login.defaults.password      = password

and then bootstrap it

(inside bootstrap.php, add this)

   /*
     * Initialize router rewriting via .ini file.
     */
    protected function _initRewrite()
    {
        $router = Zend_Controller_Front::getInstance()->getRouter();
        $router->addConfig(new Zend_Config_Ini(APPLICATION_PATH. "/configs/routes.ini",
                'production'), 'routes');
    } 

You could then access the login page with www.site.com/login/yourname/yourpass

or get to the home page via www.site.com/home

http://www.devpatch.com/2010/02/load-routes-from-routes-ini-config-file-in-zend-application-bootstrap/

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

like image 91
TuK Avatar answered Dec 13 '25 10:12

TuK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!