yii url manager - Yii router rule to redirect a keyword to an action's $_GET Parametric -


In Yii, do the router rule for a keyword "Translate" for a keyword "$ _GET" in the URL Is it possible to use? Paramatric?

What I need is to give this URL:

http://example.com/MyModule/MyController/index/foo

To indicate:

http://example.com?r=MyModule/MyController/index&id=12

Where < Code> foo issue 12 .

And, since I am using "path" urlFormat, and index and id = , pointing to the URL given above Should:

http://example.com/MyModule/MyController/12

This is likely to set the rule in the config file for urlManager component ?

Your action should accept a parameter $ id :

  Public Function Action View ($ ID) {$ Model = $ this- & gt; LoadModel ($ id);   

What you have to do, modify the load model function in the same controller:

  / ** * @ string or model to the absolute integer or ID Slug can be loaded * / Public function LoadModel ($ ID) {if (is_numeric ($ id)) {$ model = Page :: model () - & gt; FindByPk ($ id); } And {$ model = page :: model () - & gt; Search ('slug =: slug', array (': slug' = & gt; $ id)); } If ($ model === null) throws new CHTPX (404, 'Requested page does not exist.'); If the ($ model-> hatativit ('deleted') and amp; $ amp; $ model- & gt; has been removed) new CHttpException throw (404, 'Requested page has been removed for reasons of regulation. '); // has not been published, if $ (model- & gt; heatitivet ('has been published') & amp;; $ model- & gt; do not display if new) CHttpException (404, The requested page has not been published. '); Return model $; }   

Then, you will need to modify urlManager rules to accept string instead of one ID:

Remove : \ d + < / Code> In the default rule below:

  '& lt; Controller: \ w + & gt; / & Lt; Id: \ d + & gt; ' = & Gt; '& Lt; Controller & gt; / View ',   

should be:

 ' controller: \ w + & gt; / & Lt; Id & gt; ; '= & Gt; Note: One more thing is that if you are going this way, make sure the slug is unique in your database, and you must also apply the verification rule in the model:  
  Array ('slug', 'unique'),    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -