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


PHP ActiveRecord::formName方法代码示例

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


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

示例1: 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

示例2: init

 public function init()
 {
     parent::init();
     if (!$this->hasModel() || !isset($this->model->{$this->attribute}) && !is_null($this->model->{$this->attribute}) || is_null($this->data) && empty($this->attributeLabel)) {
         throw new InvalidConfigException("Either 'model' and 'attribute' and 'attributeLabel' properties must be specified.");
     }
     /** @var ActiveRecord[] $models */
     $models = $this->model->{$this->attribute};
     if (!$this->data && is_array($models) && current($models) instanceof ActiveRecord) {
         $primaryKey = $models[0]->primaryKey();
         if (!isset($primaryKey[0])) {
             throw new Exception('"' . get_class($models[0]) . '" must have a primary key.');
         }
         $this->data = ArrayHelper::map($models, $primaryKey[0], $this->attributeLabel);
     }
     $this->scriptOptions['data'] = $this->data;
     if (!isset($this->scriptOptions['templateItem']) || !$this->scriptOptions['templateItem']) {
         $this->scriptOptions['templateItem'] = Html::tag('li', '{text}' . Html::a(Html::tag('span', '', ['class' => 'glyphicon glyphicon-remove']), '#', ['class' => 'checkbox-multiple-remove-item', 'onclick' => 'return false;']), ['class' => 'checkbox-multiple-item']);
     }
     if (!isset($this->scriptOptions['templateCheckbox']) || !$this->scriptOptions['templateCheckbox']) {
         $this->scriptOptions['templateCheckbox'] = Html::checkbox($this->model->formName() . '[' . $this->attribute . '][]', true, ['value' => '{id}']);
     }
     if (!isset($this->scriptOptions['templateResultItem']) || !$this->scriptOptions['templateResultItem']) {
         $this->scriptOptions['templateResultItem'] = Html::tag('li', '{text}', ['class' => 'checkbox-multiple-result-item']);
     }
     if (!isset($this->scriptOptions['templateInput']) || !$this->scriptOptions['templateInput']) {
         $this->scriptOptions['templateInput'] = Html::textInput('checkbox-multiple-input', '', ['class' => 'form-control']);
     }
     if (!isset($this->scriptOptions['errorMessage'])) {
         $this->scriptOptions['errorMessage'] = Yii::t('app', 'Error');
     }
     if (!isset($this->scriptOptions['templateResultError']) || !$this->scriptOptions['templateResultError']) {
         $this->scriptOptions['templateResultError'] = Html::tag('li', '{text}', ['class' => 'checkbox-multiple-result-error']);
     }
     if (!isset($this->scriptOptions['warningMessage'])) {
         $this->scriptOptions['warningMessage'] = Yii::t('app', 'No results');
     }
     if (!isset($this->scriptOptions['templateResultWarning']) || !$this->scriptOptions['templateResultWarning']) {
         $this->scriptOptions['templateResultWarning'] = Html::tag('li', '{text}', ['class' => 'checkbox-multiple-result-warning']);
     }
     if (empty($this->placeholder)) {
         $this->placeholder = Yii::t('app', 'Search ...');
     }
     $this->scriptOptions['templatePlaceholder'] = Html::tag('li', $this->placeholder, ['class' => 'checkbox-multiple-placeholder']);
     Html::addCssClass($this->options, 'checkbox-multiple');
     $this->registerAsset();
     $this->registerSlimScrollAsset();
     $this->registerClientScript();
 }
开发者ID:diiimonn,项目名称:yii2-widget-checkbox-multiple,代码行数:49,代码来源:CheckboxMultiple.php

示例3: formName

 public function formName()
 {
     if ($this->scenario == 'search') {
         return '';
     }
     return parent::formName();
 }
开发者ID:jarrus90,项目名称:yii2-website-comments,代码行数:7,代码来源:Comment.php

示例4: formName

 public function formName()
 {
     $class = get_class($this);
     if (!isset(self::$formNameCache[$class])) {
         self::$formNameCache[$class] = parent::formName();
     }
     return self::$formNameCache[$class];
 }
开发者ID:laszlovl,项目名称:yii2-staticactiverecord,代码行数:8,代码来源:ActiveRecord.php

示例5: formName

 /**
  * @inheritdoc
  */
 public function formName()
 {
     $name = parent::formName();
     if ($this->language) {
         $name .= '_' . $this->language;
     }
     return $name;
 }
开发者ID:maddoger,项目名称:yii2-cms-website,代码行数:11,代码来源:PageI18n.php

示例6: load

 /**
  * Load data into model. Using setters
  * @see [[Model::load()]]
  * @param array $data
  * @param null $formName
  * @return bool
  */
 public function load($data, $formName = null)
 {
     $scope = $formName === null ? $this->model->formName() : $formName;
     if ($scope != '' && isset($data[$scope])) {
         $data = $data[$scope];
     }
     foreach ($data as $attribute => $value) {
         $this->model->{$attribute} = $value;
     }
     return true;
 }
开发者ID:dawei101,项目名称:yii2-admin-module,代码行数:18,代码来源:Form.php

示例7: saveTranslations

 /**
  * @param array $data
  * @param string|null $formName
  */
 public function saveTranslations($data = [], $formName = null)
 {
     $scope = $formName === null ? $this->owner->formName() : $formName;
     if ($scope === '' && !empty($data)) {
         $this->saveData($data);
         return;
     }
     if (isset($data[$scope])) {
         $this->saveData($data[$scope]);
         return;
     }
 }
开发者ID:gbksoft,项目名称:yii2-multilingual,代码行数:16,代码来源:Multilingual.php

示例8: afterSave

 public function afterSave()
 {
     $data = [];
     if (isset($_POST[$this->owner->formName()])) {
         $data = $_POST[$this->owner->formName()];
     }
     if ($data) {
         foreach ($data as $attribute => $value) {
             if (!in_array($attribute, $this->relations)) {
                 continue;
             }
             if (is_array($value)) {
                 $relation = $this->owner->getRelation($attribute);
                 if ($relation->via !== null) {
                     /** @var ActiveRecord $foreignModel */
                     $foreignModel = $relation->modelClass;
                     $this->owner->unlinkAll($attribute, true);
                     if (is_array(current($value))) {
                         foreach ($value as $data) {
                             if (isset($data[$foreignModel::primaryKey()[0]]) && $data[$foreignModel::primaryKey()[0]] > 0) {
                                 $fm = $foreignModel::findOne($data[$foreignModel::primaryKey()[0]]);
                                 $fm->load($data, '');
                                 $this->owner->link($attribute, $fm);
                             }
                         }
                     } else {
                         foreach ($value as $fk) {
                             if (preg_match('~^\\d+$~', $fk)) {
                                 $this->owner->link($attribute, $foreignModel::findOne($fk));
                             }
                         }
                     }
                 }
             } else {
                 $this->owner->unlinkAll($attribute, true);
             }
         }
     }
 }
开发者ID:diiimonn,项目名称:yii2-behavior-relation-follow,代码行数:39,代码来源:RelationFollowBehavior.php

示例9: __construct

 /**
  * ImportLog constructor.
  * @param iImportFile $ImportFile
  * @param ActiveRecord $activeRecordLog
  * @throws \Exception
  */
 public function __construct(iImportFile $ImportFile, ActiveRecord $activeRecordLog)
 {
     $formName = strtolower($activeRecordLog->formName());
     $this->setType($formName . '_type');
     $this->setFilename($formName . '_filename');
     $this->setFilelastdate($formName . '_filelastdate');
     $this->setRownum($formName . '_rownum');
     $this->setMessage($formName . '_message');
     $this->setImportFile($ImportFile);
     $this->setActiveRecordLog($activeRecordLog);
     if (!$this->getActiveRecordLog()->hasAttribute('id_logreport')) {
         throw new \Exception('Отсутствует свойство id_logreport');
     }
     $this->getActiveRecordLog()->id_logreport = $ImportFile->getLogReport()->primaryKey;
     $this->getActiveRecordLog()->{$this->getType()} = 1;
     $this->getActiveRecordLog()->{$this->getFilename()} = $ImportFile->getFileName();
     $this->getActiveRecordLog()->{$this->getFilelastdate()} = $ImportFile->getFileLastDate();
     $this->getActiveRecordLog()->{$this->getRownum()} = $ImportFile->getRow();
     $this->getActiveRecordLog()->{$this->getMessage()} = 'Запись добавлена.';
 }
开发者ID:vovancho,项目名称:yii2test,代码行数:26,代码来源:ImportLog.php

示例10: register

 /**
  * @param ActiveRecord $model
  * @param null|string $language
  * @param array|null $metaTagsToFetch
  */
 public static function register(ActiveRecord $model, $language = null, $metaTagsToFetch = null)
 {
     $metaTags = MetaTagContent::find()->where([MetaTagContent::tableName() . '.model_id' => $model->id])->andWhere([MetaTagContent::tableName() . '.model_name' => $model->formName()])->joinWith(['metaTag']);
     if (is_array($metaTagsToFetch)) {
         $metaTags->andWhere([MetaTag::tableName() . '.name' => $metaTagsToFetch]);
     } else {
         $metaTags->andWhere([MetaTag::tableName() . '.is_active' => 1]);
     }
     if (!is_string($language)) {
         $language = Yii::$app->language;
     }
     $metaTags->andWhere([MetaTagContent::tableName() . '.language' => $language]);
     /** @var MetaTagContent[] $metaTags */
     $metaTags = $metaTags->all();
     foreach ($metaTags as $metaTag) {
         $content = $metaTag->getMetaTagContent();
         foreach ($model->attributes as $name => $value) {
             $content = str_replace("[{$name}]", $value, $content);
         }
         if (!empty($content)) {
             if (strtolower($metaTag->metaTag->name) === MetaTag::META_TITLE_NAME) {
                 Yii::$app->getView()->title = $content;
             } elseif (strtolower($metaTag->metaTag->name) === MetaTag::META_SEO_TEXT) {
                 self::$seoText .= $content;
             } elseif (strtolower($metaTag->metaTag->name) === MetaTag::META_ROBOTS) {
                 if ($content) {
                     Yii::$app->view->registerMetaTag(['name' => 'robots', 'content' => 'noindex, FOLLOW'], 'robots');
                 }
             } else {
                 if ($metaTag->metaTag->name) {
                     Yii::$app->view->registerMetaTag([$metaTag->metaTag->is_http_equiv ? 'http-equiv' : 'name' => $metaTag->metaTag->name, 'content' => $content], $metaTag->metaTag->name);
                 }
             }
         }
     }
 }
开发者ID:hanterrian,项目名称:yii2-meta-tag-module,代码行数:41,代码来源:MetaTagRegister.php

示例11: getRelationRoutes

 /**
  * @param \yii\db\ActiveRecord $model
  * @param \yii\db\ActiveRecord $relatedModel
  * @param \yii\db\ActiveQuery $relation
  * @return array array with three arrays: create, search and index routes
  */
 public static function getRelationRoutes($model, $relatedModel, $relation)
 {
     if (($route = Yii::$app->crudModelsMap[$relatedModel::className()]) === null) {
         return [null, null, null];
     }
     $allowCreate = Yii::$app->user->can($relatedModel::className() . '.create');
     if ($allowCreate && $model->isNewRecord && $relation->multiple) {
         foreach ($relation->link as $left => $right) {
             if (!$relatedModel->getTableSchema()->getColumn($left)->allowNull) {
                 $allowCreate = false;
                 break;
             }
         }
     }
     if (!$allowCreate) {
         $createRoute = null;
     } else {
         $createRoute = [$route . '/update'];
         if ($relation->multiple) {
             $createRoute['hide'] = implode(',', array_keys($relation->link));
             $scope = $relatedModel->formName();
             $primaryKey = $model->getPrimaryKey(true);
             foreach ($relation->link as $left => $right) {
                 if (!isset($primaryKey[$right])) {
                     continue;
                 }
                 $createRoute[$scope][$left] = $primaryKey[$right];
             }
         }
     }
     $parts = explode('\\', $relatedModel::className());
     $relatedModelClass = array_pop($parts);
     $relatedSearchModelClass = implode('\\', $parts) . '\\search\\' . $relatedModelClass;
     $searchRoute = !class_exists($relatedSearchModelClass) ? null : [$route . '/relation', 'per-page' => 10, 'relation' => $relation->inverseOf, 'id' => Action::exportKey($model->getPrimaryKey()), 'multiple' => $relation->multiple ? 'true' : 'false'];
     $indexRoute = [$route . '/index'];
     return [$createRoute, $searchRoute, $indexRoute];
 }
开发者ID:netis-pl,项目名称:yii2-crud,代码行数:43,代码来源:FormBuilder.php

示例12: formName

 /**
  * @inheritdoc
  */
 public function formName()
 {
     if ($this->scenario == self::SCENARIO_SEARCH) {
         return StringHelper::basename(self::className()) . 'Search';
     }
     return parent::formName();
 }
开发者ID:alesar-code,项目名称:yii2-base,代码行数:10,代码来源:ActiveRecord.php

示例13: formName

 public function formName()
 {
     if ($this->scenario == 'newItem') {
         return 'MenuNewItem';
     } elseif ($this->scenario == 'updateMenuItems') {
         return 'menu-items[' . $this->id . ']';
     } else {
         return parent::formName();
     }
 }
开发者ID:maddoger,项目名称:yii2-cms-website,代码行数:10,代码来源:Menu.php

示例14: AssignToModelFromGrid

 /**
  * Присваивает выбранное значение из справочника модели, в сессии.
  * При выборе значения из справочника, значение присваивается в сессию предыдущей хлебной крошки, для формы, с которой был открыт справочник.
  * @param bool $RedirectPreviousUrl
  * @param ActiveRecord $ActiveRecord Модель к которой присваивается знаечния из справочника.
  * @param string $AttributeForeignID Имя атрибута
  * @return string
  */
 public static function AssignToModelFromGrid($RedirectPreviousUrl = True, $ActiveRecord = NULL, $AttributeForeignID = NULL)
 {
     if (Yii::$app->request->isAjax) {
         $LastBC = Proc::GetLastBreadcrumbsFromSession();
         $assigndata = filter_input(INPUT_POST, 'assigndata');
         $foreign = isset($LastBC['dopparams']['foreign']) ? $LastBC['dopparams']['foreign'] : '';
         if (!empty($foreign) && !empty($assigndata)) {
             $BC = Proc::GetBreadcrumbsFromSession();
             end($BC);
             prev($BC);
             $BC[key($BC)]['dopparams'][$foreign['model']][$foreign['field']] = $assigndata;
             $session = new Session();
             $session->open();
             $session['breadcrumbs'] = $BC;
             $session->close();
             if ($ActiveRecord instanceof ActiveRecord && is_string($AttributeForeignID)) {
                 $field = $LastBC['dopparams']['foreign']['field'];
                 if ($ActiveRecord->formName() === $LastBC['dopparams']['foreign']['model']) {
                     $ActiveRecord->{$field} = $assigndata;
                     $ActiveRecord->{$AttributeForeignID} = $foreign['id'];
                     if ($ActiveRecord->validate()) {
                         $ActiveRecord->save(false);
                     }
                 }
             }
             if ($RedirectPreviousUrl) {
                 Yii::$app->response->redirect(Proc::GetPreviousURLBreadcrumbsFromSession());
             }
         } else {
             return 'error foreign or assigndata empty AssignToModelFromGrid()';
         }
     }
 }
开发者ID:vovancho,项目名称:yii2test,代码行数:41,代码来源:Proc.php


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