0

I want to make url like this in Yii1 http://example.com/customer-name. It would list jobs for the customer-name, this customer-name will be changing dynamically for example customer-name can be customer-name=IBM or customer-name=abc-mn or customer-name=xyz

The urls will be something like this

http://example.com/IBM
http://example.com/abc-mn
http://example.com/xyz

I have tried many tutorials but when I a try nothing works for me. Also I followed the http://www.yiiframework.com/doc/guide/1.1/en/topics.url

M-Ali
  • 23
  • 5

1 Answers1

0

You new to configure the main.php config properly and have your controller action ready.

private/protected/config/main.php

'urlManager'=>array(
    //path is slash separated format aka www.url.com/controller/action/getparam/getvalue
    'urlFormat'=>'path',
    'showScriptName'=>false,
    'caseSensitive'=>true,                     
    'rules'=>array(
//site is your controller, comapny is your action and the name is get variable actionCompany is waiting for.
        '<name>' => 'site/company'
)),

private/protected/controllers/SiteController.php (alos make sure the actioname company is in accessRules if you user acceessControll filter).

public function actionCompany( $name )
{
    /* your action code */
    $this->render('test', array( 'test' => 'to_view' ) );
}

If this didn't help then you have to give us more of your code.

DonRico
  • 182
  • 12
  • Dear, URL is working fine now, but now when I get name in it display Undefined variable: name I created test view in site view test.php and just show name but throws notice of undefined name I created url testingname which makes prettry good url http://localhost/tracker-company/index.php/testingname but undefined name is showing – M-Ali May 24 '16 at 07:01
  • Mh that means that $_GET['name'] parameter wasn't passed to the action. Do you have any other urlManager rules in that rules array? The order of rules is crucial. can you maybe pastebin.com your action and if you changed your rules then urlManager also. – DonRico May 24 '16 at 07:10
  • EDIT: From your comment it seems you are not passing the $name to view while rendering the view. $this->render('test', array('name' => $name )); – DonRico May 24 '16 at 07:14
  • I am passing the $name. Below is my function public function actionCompany( $name ) { /* your action code */ $this->render('test', array( 'test' => $name ) ); } – M-Ali May 24 '16 at 07:16
  • Then on your view there should be – DonRico May 24 '16 at 07:17
  • No, I do not have any other RULES – M-Ali May 24 '16 at 07:18
  • Hehe, nice. Try to understand the mechanics, it starts to make sens if play with it for a while. Btw. you can also remove index.php from the url by using .htaccess . http://www.yiiframework.com/wiki/214/url-hide-index-php/ – DonRico May 24 '16 at 07:22