0

My code is

class WorkshopsController extends Controller
{
    public $layout = false;

    public function actionIndex($address)
    {
        echo $address;
        return $this->render('workshops.twig');
    }
} 

I want to pass any place address to above given action. how can i do that in Yii2. Address can be like "Mazyad Road, Mazyad - Al Ain - أبو ظبي - United Arab Emirates"

Chinmay Waghmare
  • 5,368
  • 2
  • 43
  • 68
abasit83
  • 13
  • 6
  • I was having same problem. But here http://stackoverflow.com/questions/32988996/url-not-accepting-alpha-numeric-paramater-yii2-app-basic i got answer. – Nana Partykar Oct 07 '15 at 09:54

1 Answers1

1

You need to request you workshops/index page with address query parameter example.com/workshops/index?address=some address. Yii will automaticaly call your action and pass query params into it.

EDIT

If you wish to use pretty url, you must specify urlManager rules for it. E.g.

rules => [
    'workshops/<address>' => 'workshops/index',
],

Also if you wish your page open when addess parameter not specified you can define rules like this:

[
    'pattern' => 'workshops/<address>',
    'route' => 'workshops/index',
    'defaults' => ['address' => ''],
]
Tony
  • 5,797
  • 3
  • 26
  • 22
  • Thanks .... One thing more.... I have a folder named "customer" in "Controllers" folder. Now "customer" folder has its own related controller files. The URL should be like "example.com/customer/documents/edit/1" in above URL "customer" is a folder, "documents" is controller file, "edit" is a action and "1" is ID now what would i do in URL Manager??? – abasit83 May 06 '15 at 09:05
  • @abasit83 i suggest to you use module, to achieve this. See [documentation](http://www.yiiframework.com/doc-2.0/guide-structure-modules.html) – Tony May 06 '15 at 12:54