-1

All I want to remove this "menu-" from the URL: "example.com/menu-burger-king"

Here is the code inside actionMenu

$url=isset($_SERVER['REQUEST_URI'])?explode("/",$_SERVER['REQUEST_URI']):false;     
    if(!is_array($url) && count($url)<=0){      
         $this->render('404-page',array(
           'header'=>true,
          'msg'=>"Sorry but we cannot find what you are looking for"
        ));         
        return ;
    }           
    $page_slug=$url[count($url)-1];
    $page_slug=str_replace('menu-','',$page_slug);
    if(isset($_GET)){               
        $c=strpos($page_slug,'?');
        if(is_numeric($c)){
            $page_slug=substr($page_slug,0,$c);
        }
    }           
    $page_slug=trim($page_slug);

I've implemented rules in config.php file as you can see below:

        'urlManager'=>array(
        'class' => 'UrlManager', 
        'urlFormat'=>'path',            
        'showScriptName'=>false,            
        'rules'=>array(     
            '' => 'store/index',
            '<action:('.$patern.')>' => 'store/<action>',
            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>'=>'<controller>/index',   '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        )           
    ),

And this is inside $pattern

$patern="cuisine|signup|signin|merchantsignup|contact|searcharea";
$patern.="|menu|checkout|paymentoption|receipt|logout|paypalinit|paypalverify";
$patern.="|OrderHistory|Profile|howItWork|forgotPassword|PageSetlanguage|stripeInit";
$patern.="|MercadoInit|RenewSuccesful|Browse|PaylineInit|Paylineverify|sisowinit";
$patern.="|PayuInit|BankDepositverify|AutoResto|AutoStreetName|AutoCategory|PayseraInit";
$patern.="|AutoFoodName|Confirmorder|Paymentbcy|Bcyinit|EpayBg|EpyInit";
$patern.="|GuestCheckout|MerchantSignupSelection|MerchantSignupinfo|CancelWithdrawal";
$patern.="|ATZinit|DepositVerify|Verification|Map|GoogleLogin|AddressBook";
$patern.="|AutoZipcode|AutoPostAddress|Item|Ty|EmailVerification|MyPoints|BtrInit|setlanguage";
$patern.="|mollieinit|mollieprocess|home|molliewebhook";
$patern.="|ip8init|ipay88verify|ipay88receiver";
$patern.="|monerisinit|confirmorder|rzrinit|rzrverify|acceptorder|declineorder|cart|restaurant";
$patern.="|voguepaynotify|voguepaysuccess|voguepayfailed|voginit|vognotify|voginit|vogsuccess";
$patern=strtolower($patern);

Frontend link is this:

<a href="<?php echo Yii::app()->createUrl("/menu-". trim($val['restaurant_slug']))?>">

When I try to remove menu- from controller and view it gives Fatal Error.

Fatal error: Uncaught exception 'CHttpException' with message 'Unable to resolve the request

Sami Khan
  • 1
  • 6

1 Answers1

0

What about something like this:

'menu-<action:[a-zA-Z0-9\-]+>' => 'store/<action>',

Assumes "burger-king" is the action in the StoreController -- if that's not your intention, add the specific requirements. (Adjust the regex as appropriate.)

ldg
  • 9,112
  • 2
  • 29
  • 44
  • Thanks for the answer... This is working for directing `'menu-' => 'store/menu-',` If I use this `'menu-' => 'store/',` it give 404 page error. – Sami Khan Feb 17 '18 at 16:58
  • Now this is working fine... `'menu-' => 'store/menu-',` but I dont want "menu-" to appear on URL. – Sami Khan Feb 17 '18 at 17:02
  • Is it possible ? – Sami Khan Feb 17 '18 at 17:04
  • Yes, you would have to use a redirect to do it server-side or [push-state](https://stackoverflow.com/questions/3338642/updating-address-bar-with-new-url-without-hash-or-reloading-the-page) to do it client-side. In either case you would want to make sure you have a rule for the "final" pattern as well. Although without knowing what your controller looks like, you would have to figure out the exact syntax and possibly have some `beforeAction()` conditionals. – ldg Feb 17 '18 at 23:33