ज़रूर है की जरूरत है। missingAction
विधि को ओवरराइड करना सबसे आसान तरीका है।
public function missingAction($actionID)
{
throw new CHttpException(404,Yii::t('yii','The system is unable to find the requested action "{action}".',
array('{action}'=>$actionID==''?$this->defaultAction:$actionID)));
}
आप बस जैसे के साथ बदलने सकता है:
यहाँ डिफ़ॉल्ट कार्यान्वयन है
public function missingAction($actionID)
{
echo 'You are trying to execute action: '.$actionID;
}
ऊपर में, $actionID
क्या आप $pageName
के रूप में उल्लेख है।
थोड़ा और अधिक शामिल लेकिन अधिक शक्तिशाली दृष्टिकोण createAction
विधि को ओवरराइड करना होगा। यहाँ डिफ़ॉल्ट कार्यान्वयन है:
/**
* Creates the action instance based on the action name.
* The action can be either an inline action or an object.
* The latter is created by looking up the action map specified in {@link actions}.
* @param string $actionID ID of the action. If empty, the {@link defaultAction default action} will be used.
* @return CAction the action instance, null if the action does not exist.
* @see actions
*/
public function createAction($actionID)
{
if($actionID==='')
$actionID=$this->defaultAction;
if(method_exists($this,'action'.$actionID) && strcasecmp($actionID,'s')) // we have actions method
return new CInlineAction($this,$actionID);
else
{
$action=$this->createActionFromMap($this->actions(),$actionID,$actionID);
if($action!==null && !method_exists($action,'run'))
throw new CException(Yii::t('yii', 'Action class {class} must implement the "run" method.', array('{class}'=>get_class($action))));
return $action;
}
}
यहाँ उदाहरण के लिए, आप के रूप में भारी हाथ के कुछ के रूप में
public function createAction($actionID)
{
return new CInlineAction($this, 'commonHandler');
}
public function commonHandler()
{
// This, and only this, will now be called for *all* pages
}
कर सकता है या आप कुछ तरह से और अधिक व्यापक कर सकता है, अपनी आवश्यकताओं के अनुसार।