本文整理汇总了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}' не существует!");
}
}
示例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();
}
}
}
示例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();
}
示例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 '';
}
示例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)
));
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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', "Автору объекта запрещено!");
}
}
示例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>';
}
}
示例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('/');
}
示例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};
}
}
}
示例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'];
}
示例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;
}
}
示例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 'Удален';
}
}