本文整理匯總了PHP中yii\web\Controller::createAction方法的典型用法代碼示例。如果您正苦於以下問題:PHP Controller::createAction方法的具體用法?PHP Controller::createAction怎麽用?PHP Controller::createAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yii\web\Controller
的用法示例。
在下文中一共展示了Controller::createAction方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: createAction
/**
* Creates an action based on the given action ID.
* The method first checks if the action ID has been declared in [[actions()]]. If so,
* it will use the configuration declared there to create the action object.
* If not, it will look for a controller method whose name is in the format of `actionXyz`
* where `Xyz` stands for the action ID. If found, an [[InlineAction]] representing that
* method will be created and returned.
* @param string $id the action ID.
* @throws Exception
* @return \yii\base\Action the newly created action instance. Null if the ID doesn't resolve into any action.
*/
public function createAction($id)
{
$action = parent::createAction($id);
if (empty($action)) {
throw new Exception("Method not found", Exception::METHOD_NOT_FOUND);
}
$this->prepareActionParams($action);
return $action;
}
示例2: initRequest
/**
* Request has to be sent as POST and with Content-type: application/json
* @throws \yii\web\HttpException
*/
private function initRequest($id)
{
list($contentType) = explode(";", Yii::$app->request->getContentType());
//cut charset
$headers = Yii::$app->request->getHeaders();
if (!empty($id) || !Yii::$app->request->getIsOptions() && null !== $headers->get('Origin') && (!Yii::$app->request->getIsPost() || empty($contentType) || $contentType != "application/json")) {
throw new HttpException(404, "Page not found");
}
//Call beforeActions on modules and controller to run all filters in behaviors() methods
$action = parent::createAction('');
// call beforeAction on modules
foreach ($this->getModules() as $module) {
if (!$module->beforeAction($action)) {
break;
}
}
// call beforeAction on controller
$this->beforeAction($action);
}
示例3: createAction
public function createAction($id)
{
$config = $this->_internalActions[$id];
return $config ? Yii::createObject($config, [$id, $this]) : parent::createAction($id);
}