コード例 #1
0
 /**
  * Creates a new model.
  * @return \Leaps\Db\ActiveRecordInterface the model newly created
  * @throws ServerErrorHttpException if there is any error when creating the model
  */
 public function run()
 {
     if ($this->checkAccess) {
         call_user_func($this->checkAccess, $this->id);
     }
     /* @var $model \Leaps\Db\ActiveRecord */
     $model = new $this->modelClass(['scenario' => $this->scenario]);
     $model->load(Leaps::$app->getRequest()->getBodyParams(), '');
     if ($model->save()) {
         $response = Leaps::$app->getResponse();
         $response->setStatusCode(201);
         $id = implode(',', array_values($model->getPrimaryKey(true)));
         $response->getHeaders()->set('Location', Url::toRoute([$this->viewAction, 'id' => $id], true));
     } elseif (!$model->hasErrors()) {
         throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
     }
     return $model;
 }
コード例 #2
0
 /**
  * Creates a URL for the given action and model.
  * This method is called for each button and each row.
  * @param string $action the button name (or action ID)
  * @param \Leaps\Db\ActiveRecord $model the data model
  * @param mixed $key the key associated with the data model
  * @param integer $index the current row index
  * @return string the created URL
  */
 public function createUrl($action, $model, $key, $index)
 {
     if ($this->urlCreator instanceof Closure) {
         return call_user_func($this->urlCreator, $action, $model, $key, $index);
     } else {
         $params = is_array($key) ? $key : ['id' => (string) $key];
         $params[0] = $this->controller ? $this->controller . '/' . $action : $action;
         return Url::toRoute($params);
     }
 }
コード例 #3
0
ファイル: Captcha.php プロジェクト: smallmirror62/framework
 /**
  * Returns the options for the captcha JS widget.
  * @return array the options
  */
 protected function getClientOptions()
 {
     $route = $this->captchaAction;
     if (is_array($route)) {
         $route[CaptchaAction::REFRESH_GET_VAR] = 1;
     } else {
         $route = [$route, CaptchaAction::REFRESH_GET_VAR => 1];
     }
     $options = ['refreshUrl' => Url::toRoute($route), 'hashKey' => "leapsCaptcha/{$route[0]}"];
     return $options;
 }