php geek
php geek

Reputation: 219

cakephp Url issue?

In Cakephp how can I use first parameter in Url, which is just after the name of the controller. I have customize the URL using route.php. My url is Like

          http://www.example.com/Destination/india/pune

form this Url "Destination" is controller. and i would like to access India as parameter.

Upvotes: 0

Views: 72

Answers (3)

AKKAweb
AKKAweb

Reputation: 3807

This can be easily accomplished using routes. However, you have to know what action within your controller is the parameter going to be passed to.

As an example you could have the following:

class DestinationsController extends AppController{

    public function view($country = null, $city = null){
        // Your logic can go here as to pull the right info from Db and display it on the view
        // Here you can access $country which might have India as the value
        // And if the only country you will be working with is India, then you can have
        // public function india($city = null) <===> This is not recommended
    }
}

And your route.php could be like

Router::connect(
        '/destination/:country/:city',
        array(
              'controller' => 'destinations',
              'action' => 'view'
        ),
        array(
            'pass' => array('country','city')
        )   
    );

Upvotes: 0

FrontEnd Expert
FrontEnd Expert

Reputation: 5803

you can check it ---

using :- $this->params

Just for giggles try $this->params['data']. I don't know why but for some reason it shows form data in there for me.

The documentation has conflicting data as you can see here

http://book.cakephp.org/view/972/data.

I am guessing that if you use the FormHelper it will show up in $this->data and if you don't use the FormHelper it will show up in $this->params['form'].

Notice if you use FormHelper the name of the element will be data['Model']['element_name'] and if you just create the form manually you can name it 'element_name'. By doing the later I believe it throws it into the params['form'] instead of the $this->data.

you can check it on routes.php

Upvotes: 0

icebreaker
icebreaker

Reputation: 1274

In Config/routes.php use

Router::connect('/Destination/*', array('controller' => 'destination', 'action' => 'search'));

Upvotes: 1

Related Questions