Yii: Обращение к модели модуля на примере модуля users (из расширения yii-users-management)

Yii: Обращение к модели модуля на примере модуля users (из расширения yii-users-management) Установил расширение yii-user-management (YUM), связываю автора материала (модель Material) по id с пользователем из таблицы user (модель YumUser в модуле yii-user-management)

Настраиваем связь между Material (в базе есть поле author_id для авторства статьи) с модулем yii-user-management.

В relations у модели protected/models/Material.php добавляем импорт моделей и обращаемся как будто модель YumUser находится не в модуле users, а где все основные модели:

public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		Yii::import('application.modules.user.models.*');
		return array(
			'author' => array(self::BELONGS_TO, 'YumUser', 'author_id'),
			'comments' => array(self::HAS_MANY, 'Comment', 'material_id', 'condition'=>'comments.status='.Comment::STATUS_APPROVED, 'order'=>'comments.create_time ASC'),
			'commentCount' => array(self::STAT, 'Comment', 'material_id', 'condition'=>'status='.Comment::STATUS_APPROVED),
		);
	}







Источник: loco.ru

almix
Разработчик Loco, автор статей по веб-разработке на Yii, CodeIgniter, MODx и прочих инструментах. Создатель Team Sense.

Вы можете почитать все статьи от almix'а.



Другие статьи по этой теме:

Комментарии (0)     Подпишитесь на RSS комментариев к этой статье.