dev-master
9999999-dev
MIT
The Requires
by Melnikov Ruslan
orm extension yii2
1.0.0
1.0.0.0
MIT
The Requires
by Melnikov Ruslan
orm extension yii2
Wallogit.com
2017 © Pedro Peláez
The preferred way to install this extension is through composer., (*1)
Either run, (*2)
php composer.phar require --prefer-dist mrssoft/yii2-link-relative "*"
or add, (*3)
"mrssoft/yii2-link-relative": "*"
to the require section of your composer.json file., (*4)
Виджет:, (*5)
echo LinkRelativeWidget::widget([
'model' => $model, //Базовая модель
'relationName' => 'items', //Название отношения (конечного)
'attributeTitle' => 'title', //Атрибут для вывода в таблице
'viaToElementName' => 'item',
'ajaxUrl' => ['item/search'], //Ссылка на поиск элементов
'placeholder' => 'Поиск товара...',
'name' => 'Товар' //Название элементов в таблице
]);
Поведение базовой модели:, (*6)
public function behaviors()
{
return [
[
'class' => SaveRelationBehavior::class,
'relationName' => 'items'
],
];
}
Действие для поиска элементов:, (*7)
public function actionSearch($search = null)
{
$out = ['results' => ['id' => '', 'text' => '']];
if ($search !== null) {
$data = Item::find()
->select(['CONCAT(`type`, " ", `name`) as text', 'id'])
->andWhere(['like', 'name', $search])
->orWhere(['like', 'type', $search])
->orderBy('text')
->limit(20)
->asArray()
->all();
$out['results'] = array_values($data);
}
Yii::$app->response->format = Response::FORMAT_JSON;
return $out;
}
MIT
orm extension yii2
MIT
orm extension yii2