本文整理汇总了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);
}