当前位置: 首页>>代码示例>>PHP>>正文


PHP db\ActiveRecord类代码示例

本文整理汇总了PHP中yii\db\ActiveRecord的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord类的具体用法?PHP ActiveRecord怎么用?PHP ActiveRecord使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ActiveRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processOutput

 /**
  * Process output. Throw error when not success with unknown reason.
  * @param boolean      $success
  * @param ActiveRecord $model
  *
  * @return ActiveRecord
  * @throws \yii\web\ServerErrorHttpException
  */
 protected static function processOutput($success, $model)
 {
     if (!$success && !$model->hasErrors()) {
         throw new ServerErrorHttpException('Error with unknown reason.');
     }
     return $model;
 }
开发者ID:sangkil,项目名称:application,代码行数:15,代码来源:Api.php

示例2: getCreateUpdateResponse

 /**
  * @param ActiveRecord $model
  * @param array $actions Custom actions array in the form of
  * ```php
  * 'name' => function() {
  *
  * }
  * ```
  * @param bool $addDefaultActions If true default actions will be added
  * @return \yii\web\Response
  * @throws BadRequestHttpException
  */
 protected function getCreateUpdateResponse($model, $actions = [], $addDefaultActions = true)
 {
     $defaultActions = [AdminHtml::ACTION_SAVE_AND_STAY => function () use($model) {
         /** @var Controller | CrudControllerTrait $this */
         return $this->redirect(['update', 'id' => $model->getPrimaryKey()]);
     }, AdminHtml::ACTION_SAVE_AND_CREATE => function () use($model) {
         /** @var Controller | CrudControllerTrait $this */
         if ($url = Url::previous($this->createUrlParam)) {
             Url::remember(null, $this->createUrlParam);
             return $this->redirect($url);
         }
         return $this->redirect(['create']);
     }, AdminHtml::ACTION_SAVE_AND_LEAVE => function () use($model) {
         /** @var Controller | CrudControllerTrait $this */
         if ($url = \Yii::$app->request->get('return')) {
             return $this->redirect($url);
         }
         if ($url = Url::previous($this->indexUrlParam)) {
             Url::remember(null, $this->indexUrlParam);
             return $this->redirect($url);
         }
         return $this->redirect(['index']);
     }];
     if ($addDefaultActions) {
         $actions = array_merge($defaultActions, $actions);
     }
     $actionName = \Yii::$app->request->post(AdminHtml::ACTION_BUTTON_NAME, AdminHtml::ACTION_SAVE_AND_LEAVE);
     if (isset($actions[$actionName])) {
         return call_user_func($actions[$actionName]);
     } else {
         throw new BadRequestHttpException('Unknown action: ' . $actionName);
     }
 }
开发者ID:omnilight,项目名称:yz2-admin,代码行数:45,代码来源:CrudControllerTrait.php

示例3: init

 public function init()
 {
     parent::init();
     $this->owner->on(ActiveRecord::EVENT_AFTER_INSERT, [$this, 'save']);
     $this->owner->on(ActiveRecord::EVENT_AFTER_UPDATE, [$this, 'save']);
     $this->owner->on(ActiveRecord::EVENT_BEFORE_DELETE, [$this, 'unlink']);
 }
开发者ID:vtvz,项目名称:yii2-relations,代码行数:7,代码来源:BaseRelation.php

示例4: run

 /**
  * @param integer $type
  * @param \yii\db\ActiveRecord $object
  */
 public function run($type, $object)
 {
     $pkey = $object->primaryKey();
     $pkey = $pkey[0];
     $data = ['table' => $object->tableName(true), 'model_id' => $object->getPrimaryKey(), 'type' => $type, 'date' => date('Y-m-d H:i:s', time())];
     switch ($type) {
         case self::EVT_INSERT:
             $data['field_name'] = $pkey;
             $this->saveField($data);
             break;
         case self::EVT_UPDATE:
             foreach ($this->updatedFields as $updatedFieldKey => $updatedFieldValue) {
                 $data['field_name'] = $updatedFieldKey;
                 $data['old_value'] = $updatedFieldValue;
                 $data['new_value'] = $object->{$updatedFieldKey};
                 $this->saveField($data);
             }
             break;
         case self::EVT_DELETE:
             $data['field_name'] = $pkey;
             $this->saveField($data);
             break;
         case self::EVT_UPDATE_PK:
             $data['field_name'] = $pkey;
             $data['old_value'] = $object->getOldPrimaryKey();
             $data['new_value'] = $object->{$pkey};
             $this->saveField($data);
             break;
     }
 }
开发者ID:cubiclab,项目名称:project-cube,代码行数:34,代码来源:ChangedocManager.php

示例5: _delete

 protected function _delete(ActiveRecord $model)
 {
     $id = Yii::$app->request->post('id');
     $model->findOne($id)->delete();
     //        $model::deleteAll($id);
     return $this->_success();
 }
开发者ID:nisnaker,项目名称:yii2-template,代码行数:7,代码来源:Base.php

示例6: relation

 public static function relation(ActiveRecord $model, $relation_name, $options = [])
 {
     /* @var ActiveRecord|YcmModelUtilTrait $model */
     $relation = $model->getRelation($relation_name);
     $config = [$relation_name, 'widget', 'widgetClass' => Select2::className(), 'data' => RelationHelper::getSelectChoices($model, $relation_name), 'hideSearch' => false, 'options' => ['multiple' => $relation->multiple, 'placeholder' => 'Select...'], 'pluginOptions' => ['allowClear' => true]];
     return ArrayHelper::merge($config, $options);
 }
开发者ID:vladdnepr,项目名称:yii2-ycm-utils,代码行数:7,代码来源:EditHelper.php

示例7: testRenderDualNotController

 /**
  * @test
  */
 public function testRenderDualNotController()
 {
     $controller = new \yii\db\ActiveRecord();
     $controller->attachBehavior('RenderDual', new \yii2renderdual\RenderDual());
     $this->setExpectedException('Exception');
     $render = $controller->renderDual('view', ['foo' => 'bar'], 'foo bar');
 }
开发者ID:felixmaier1989,项目名称:yii2-renderdual,代码行数:10,代码来源:RenderDualTest.php

示例8: addErrorMessagesFromModel

 /**
  * @param ActiveRecord $model
  */
 public function addErrorMessagesFromModel(ActiveRecord $model)
 {
     foreach ($model->getErrors() as $fieldWithErrors) {
         foreach ($fieldWithErrors as $error) {
             $this->addMessage(null, $error, Message::ALERT);
         }
     }
 }
开发者ID:pbabilas,项目名称:bcode,代码行数:11,代码来源:AbstractController.php

示例9: getUrl

 /**
  * @param $direction string
  * @param $model ActiveRecord
  * @return array
  */
 protected function getUrl($direction, ActiveRecord $model)
 {
     $url = !empty($this->url) ? $this->url : ['order'];
     $url['direction'] = $direction;
     $url['attribute'] = $this->attribute;
     $url['id'] = $model->getPrimaryKey();
     return $url;
 }
开发者ID:Wubbleyou,项目名称:yii2-ordermodel,代码行数:13,代码来源:OrderModelColumn.php

示例10: attach

 /**
  * @inheritdoc
  *
  * @param ActiveRecord $owner
  *
  * @throws ErrorException
  */
 public function attach($owner)
 {
     if (!self::$_eventSwitched) {
         Event::on($owner->className(), VekActiveRecord::EVENT_TO_SAVE_MULTIPLE, [self::className(), 'logToSaveMultiple']);
         Event::on($owner->className(), VekActiveRecord::EVENT_SAVED_MULTIPLE, [self::className(), 'logSavedMultiple']);
     }
     parent::attach($owner);
 }
开发者ID:VEKsoftware,项目名称:yii2-log-behavior,代码行数:15,代码来源:MultipleLog.php

示例11: getFilenameFor

 /**
  * @param  ActiveRecord $activeRecord
  * @param               $attribute
  * @param null $extension
  *
  * @return string
  */
 public function getFilenameFor($activeRecord, $attribute, $extension = null)
 {
     $path = Inflector::camel2id((new \ReflectionClass($activeRecord))->getShortName());
     $basename = implode('-', $activeRecord->getPrimaryKey(true)) . '-' . $attribute;
     if ($extension) {
         $basename .= '.' . $extension;
     }
     return $path . DIRECTORY_SEPARATOR . $basename;
 }
开发者ID:voodoo-mobile,项目名称:yii2-upload,代码行数:16,代码来源:Writer.php

示例12: castModel

 /**
  * Get an array representing the properties of a model.
  *
  * @param \yii\db\ActiveRecord $model
  * @return array
  */
 public static function castModel(ActiveRecord $model)
 {
     $attributes = array_merge($model->getAttributes(), $model->getRelatedRecords());
     $results = [];
     foreach ($attributes as $key => $value) {
         $results[Caster::PREFIX_VIRTUAL . $key] = $value;
     }
     return $results;
 }
开发者ID:yiisoft,项目名称:yii2-shell,代码行数:15,代码来源:YiiCaster.php

示例13: findOrderNum

 /**
  * Find and set order numeric
  */
 public function findOrderNum()
 {
     if (!$this->owner->{$this->attribute}) {
         $maxOrderNum = (int) (new Query())->select("MAX({$this->attribute})")->from($this->owner->tableName())->scalar();
         $this->owner->{$this->attribute} = $maxOrderNum + $this->step;
     }
 }
开发者ID:roboapp,项目名称:base,代码行数:10,代码来源:SortableBehavior.php

示例14: init

 public function init()
 {
     $this->id = $this->model->formName();
     $this->action = RequestModule::getPopupUrl(['type' => $this->model->tableName()]);
     $this->fieldConfig = ['template' => '<div class="row">{input}{error}</div>', 'errorOptions' => ['class' => 'errorMessage']];
     parent::init();
 }
开发者ID:tolik505,项目名称:bl,代码行数:7,代码来源:CustomForm.php

示例15: run

 public function run($action)
 {
     $this->type = Yii::$app->request->get('type');
     $this->behaviorName = Yii::$app->request->get('behaviorName');
     $this->galleryId = Yii::$app->request->get('galleryId');
     $pkNames = call_user_func([$this->types[$this->type], 'primaryKey']);
     $pkValues = explode($this->pkGlue, $this->galleryId);
     $pk = array_combine($pkNames, $pkValues);
     $this->owner = call_user_func([$this->types[$this->type], 'findOne'], $pk);
     $this->behavior = $this->owner->getBehavior($this->behaviorName);
     switch ($action) {
         case 'delete':
             return $this->actionDelete(Yii::$app->request->post('id'));
             break;
         case 'ajaxUpload':
             return $this->actionAjaxUpload();
             break;
         case 'changeData':
             return $this->actionChangeData(Yii::$app->request->post('photo'));
             break;
         case 'order':
             return $this->actionOrder(Yii::$app->request->post('order'));
             break;
         default:
             throw new HttpException(400, 'Action do not exists');
             break;
     }
 }
开发者ID:tamvodopad,项目名称:yii2-gallery-manager,代码行数:28,代码来源:GalleryManagerAction.php


注:本文中的yii\db\ActiveRecord类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。