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:
To indicate: Where < Code> foo issue And, since I am using "path" urlFormat, and This is likely to set the rule in the config file for urlManager component ? Your action should accept a parameter What you have to do, modify the load model function in the same controller: Then, you will need to modify urlManager rules to accept string instead of one ID: Remove should be: http://example.com/MyModule/MyController/index/foo
http://example.com?r=MyModule/MyController/index&id=12
12 .
id = , pointing to the URL given above Should:
http://example.com/MyModule/MyController/12
$ id :
Public Function Action View ($ ID) {$ Model = $ this- & gt; LoadModel ($ id);
/ ** * @ 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 $; }
: \ d + < / Code> In the default rule below:
'& lt; Controller: \ w + & gt; / & Lt; Id: \ d + & gt; ' = & Gt; '& Lt; Controller & gt; / View ',
' 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
Post a Comment