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


PHP ActiveRecord::model方法代码示例

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


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

示例1: validateAttribute

 protected function validateAttribute($object, $attribute)
 {
     $object = ActiveRecord::model($object->model_id)->findByPk($object->object_id);
     if (!$object) {
         $this->addError($object, $attribute, "Объекта с моделью '{$object->model_id}' и ID '{$object->object_id}' не существует!");
     }
 }
开发者ID:nizsheanez,项目名称:kur.ru,代码行数:7,代码来源:ObjectExistsValidator.php

示例2: run

 public function run()
 {
     Yii::import('application.models.*');
     $path = Yii::app()->request->getParam('path');
     $id = Yii::app()->request->getParam('id');
     $widget = Yii::app()->request->getParam('widget');
     $data = AdminWidget::getWidgetDataByPath($widget);
     $modelName = $data['model'];
     $tableName = ActiveRecord::model($modelName)->tableName();
     $d = Yii::app()->db->createCommand('select MAX(sort),MIN(sort) FROM ' . $tableName . ' where active = 1')->queryRow(false);
     $max = intval($d[0]);
     $min = intval($d[1]);
     $pk = ActiveRecord::model($modelName)->tableSchema->primaryKey;
     $model = ActiveRecord::model($modelName)->findByPk($id);
     if ($model->sort != $max && $path == 'down' || $model->sort != $min && $path == 'up') {
         if ($path == 'down') {
             $s = $model->sort + 1;
             $c = Yii::app()->db->createCommand("update {$tableName} set sort = sort-1 where sort = {$s}")->execute();
             $r = Yii::app()->db->createCommand("update {$tableName} set sort = sort+1 where {$pk} = {$id}")->execute();
         } else {
             $s = $model->sort - 1;
             $c = Yii::app()->db->createCommand("update {$tableName} set sort = sort+1 where sort = {$s}")->execute();
             $r = Yii::app()->db->createCommand("update {$tableName} set sort = sort-1 where {$pk} = {$id}")->execute();
         }
     }
 }
开发者ID:arossokha,项目名称:ex-comment,代码行数:26,代码来源:SortWidget.php

示例3: __construct

 /**
  * Creates a new pagination object
  *
  * @param $model A string containg the name of model to be used or the model itself (can use named scopes)
  * @param $per_page The number of records per pege to display
  * @param $query Query data to be passed when quering ActiveRecord
  * @return ArPagination
  */
 public function __construct($model, $per_page = 10, $query = array())
 {
     $this->model = is_string($model) ? ActiveRecord::model($model) : $model;
     $this->query = $query;
     $this->per_page = $per_page;
     $this->config = $this->default_config();
 }
开发者ID:EscoreBu,项目名称:metrics-bot,代码行数:15,代码来源:ArPagination.php

示例4: getString

 public static function getString($model_id, $object_id)
 {
     $model = ActiveRecord::model($model_id)->findByPk($object_id);
     if ($model) {
         $result = CHtml::listData($model->tags, 'id', 'name');
         return implode(', ', $result);
     }
     return '';
 }
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:9,代码来源:Tag.php

示例5: findAllAttaches

 public function findAllAttaches()
 {
     $model     = $this->getOwner();
     $object_id = $model->isNewRecord ? $this->_tmpPrefix() : $model->id;
     return ActiveRecord::model(get_class($this->getOwner()))->findAllByAttributes(array(
         'object_id' => $object_id,
         'model_id'  => get_class($model)
     ));
 }
开发者ID:nizsheanez,项目名称:kur.ru,代码行数:9,代码来源:FileManagerBehavior.php

示例6: __construct

 public function __construct($local_model, $foreign_model, $options = array())
 {
     $this->local_model = $local_model;
     $this->foreign_model = class_exists($foreign_model) ? ActiveRecord::model($foreign_model) : $foreign_model;
     $this->options = $options;
     $this->_data = null;
     $this->_newdata = null;
     $this->_changed = false;
 }
开发者ID:EscoreBu,项目名称:metrics-bot,代码行数:9,代码来源:ActiveRelation.php

示例7: validateAttribute

 protected function validateAttribute($object, $attribute)
 {
     $model = ActiveRecord::model($object->model_id)->findByPk($object->object_id);
     if (!$model) {
         $this->addError($object, $attribute, "Объекта с моделью '{$object->model_id}' и ID '{$object->object_id}' не существует!");
     } else {
         if (property_exists($object, 'target_model')) {
             $object->target_model = $model;
         }
     }
 }
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:11,代码来源:ObjectExistsValidator.php

示例8: loadModel

 /**
  * @param int|string $id
  * @param bool       $throw
  * @return ActiveRecord
  * @throws \CHttpException
  */
 public final function loadModel($id, $throw = true)
 {
     /**
      * @var ActiveRecord $model
      */
     $model = ActiveRecord::model($this->modelName);
     $model = $model->findByPk($id);
     if ($throw && null === $model) {
         throw new \CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
开发者ID:wuhailin,项目名称:composer,代码行数:18,代码来源:Controller.php

示例9: validateAttribute

 protected function validateAttribute($object, $attribute)
 {
     if (Yii::app()->user->isGuest) {
         return;
     }
     $model = ActiveRecord::model($object->model_id)->findByPk($object->object_id);
     if (!$model) {
         return;
     }
     if ($model->user_id == Yii::app()->user->id) {
         $this->addError($object, 'object_id', "Автору объекта запрещено!");
     }
 }
开发者ID:nizsheanez,项目名称:blog.ru,代码行数:13,代码来源:NotObjectAuthorValidator.php

示例10: getObject

 public function getObject()
 {
     $models = AppManager::getModels();
     if (!isset($models[$this->model_id])) {
         return;
     }
     $object = ActiveRecord::model($this->model_id)->findByPk($this->object_id);
     if ($object) {
         return $object;
     } else {
         return '<span style="color:red">не существует</span>';
     }
 }
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:13,代码来源:MetaTag.php

示例11: actionCreateTableField

 public function actionCreateTableField($model)
 {
     $model = ActiveRecord::model($model);
     $table = $model->tableName();
     $meta = $model->meta();
     if (!isset($meta['language'])) {
         $sql = "ALTER TABLE `{$table}`\r\n                          ADD `language` char(2) DEFAULT 'ru' COMMENT 'Язык' AFTER `id`";
         Yii::app()->db->createCommand($sql)->execute();
         $sql = 'ALTER TABLE `{$table}` ADD CONSTRAINT `{$table}_language_fk` FOREIGN KEY (`language`) REFERENCES `languages` (`id`) ON DELETE CASCADE ON UPDATE CASCADE';
         Yii::app()->db->createCommand($sql)->execute();
     }
     $this->redirect('/');
 }
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:13,代码来源:LanguageAdminController.php

示例12: run

 public function run($id)
 {
     $model = $this->model ? ActiveRecord::model($this->model)->findByPk($id) : $this->controller->loadModel($id);
     $model->scenario = 'update';
     $this->controller->performAjaxValidation($model);
     $attr = $_POST['attr'];
     if (isset($_POST[$attr]) && in_array($attr, $this->attributes)) {
         $model->{$attr} = trim(strip_tags($_POST[$attr]));
         if ($model->save(false)) {
             echo $model->{$attr};
         }
     }
 }
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:13,代码来源:UpdateAttrAction.php

示例13: viewAttribute

 /**
  * @param $model - profile model
  * @param $field - profile fields model item
  * @return string
  */
 public function viewAttribute($model, $field)
 {
     $relation = $model->relations();
     if ($this->params['relationName'] && isset($relation[$this->params['relationName']])) {
         $m = $model->__get($this->params['relationName']);
     } else {
         $m = ActiveRecord::model($this->params['modelName'])->findByPk($model->getAttribute($field->varname));
     }
     if ($m) {
         return $this->params['optionName'] ? $m->getAttribute($this->params['optionName']) : $m->id;
     }
     return $this->params['emptyField'];
 }
开发者ID:marsoltys,项目名称:yii2user,代码行数:18,代码来源:UWrelBelongsTo.php

示例14: refresh

 public function refresh()
 {
     if (isset($this->options['polymorphic']) && $this->options['polymorphic'] == true) {
         $as = Ra_StringHelper::underscore($this->foreign_model);
         $id_field = $as . "_id";
         $type_field = $as . "_type";
         $value = $this->local_model->{$id_field};
         return ActiveRecord::model($this->local_model->{$type_field})->find($value);
     } else {
         $foreign_field = $this->get_foreign_field($this->foreign_model);
         $foreign_key_field = $this->foreign_model->primary_key();
         $data = $this->foreign_model->find($this->local_model->{$foreign_field});
         return $data;
     }
 }
开发者ID:EscoreBu,项目名称:metrics-bot,代码行数:15,代码来源:ActiveRelationOne.php

示例15: getObjectUpdateUrl

function getObjectUpdateUrl($object_id, $model)
{
    try {
        if (!is_numeric($object_id) || !method_exists($model, 'updateUrl')) {
            return;
        }
        $object = ActiveRecord::model($model)->findByPk($object_id);
        if (!$object) {
            return;
        }
        return CHtml::link('перейти', $object->updateUrl());
    } catch (Exception $e) {
        return 'Удален';
    }
}
开发者ID:blindest,项目名称:Yii-CMS-2.0,代码行数:15,代码来源:manage.php


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