/**
  * 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
0
 /**
  * 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
0
 public function createAction($id)
 {
     $config = $this->_internalActions[$id];
     return $config ? Yii::createObject($config, [$id, $this]) : parent::createAction($id);
 }