Pages

Sunday, December 9, 2012

Hiding Controller from cakephp Url

In routes.php add the following code

  Router::connect('/*', array('controller' => 'Site', 'action' => 'display'));

What this does is each time you fire a url with "/parameter" it redirects to Site controller and display action

Now under site controller in display action add this

class SiteController extends AppController
{
    public $name="Site";
   
    public function display()
    {
        $path = func_get_args();
        //print_r($path);
        $count = count($path);
        if (!$count)
        {
             $this->redirect('/');
        }
        else
        {
            $this->render(implode('/', $path));
        }
    }
}

1 comment:

  1. Good article

    https://wordpress-special-plugin.blogspot.co.id

    ReplyDelete