$model->detachBehavior('behaviorName');
public function behaviors()
{
return [
'behaviorName'=> [
'class' => IndividualServicePriceBehavior::className(),
/// ,,,
],
];
}
public function minify(string $content):string
{
return trim(preg_replace('/>\s+</', '><', $content));
}
$this->render('another_template',['prop'=>$val]);//шаблон в этой же директории
$this->renderFile('@app/some/path/views/another_template',['prop'=>$val]);//шаблон из другого места
<?php $this->beginContent('@app/views/layouts/base.php'); ?>
//Some another content - внедрение в вывод контента вызываемого layout
<?php $this->endContent(); ?>
interface PostCommentModelInterface // можно extends ActiveRecordInterface
{
/**
* @return ActiveRecord[]|Comment[]
**/
public function findForPost();
}
class Model extends yii\base\Model
{
protected $commentModel;
public function __construct(PostCommentModelInterface $commentModel, $config = [])
{
$this->commentModel = $commentModel;
parent::__construct($config);
}
]
...
protected $commentModel;
public function __construct(\yii\container\Container $container, $config = [])
{
$this->commentModel = $container->get('\app\modules\posts\PostCommentModelInterface'');
parent::__construct($config);
}
...
like: operand 1 should be a column or DB expression, and operand 2 be a string or an array representing the values that the column or DB expression should be like. For example, ['like', 'name', 'tester'] will generate name LIKE '%tester%'. When the value range is given as an array, multiple LIKE predicates will be generated and concatenated using AND. For example, ['like', 'name', ['test', 'sample']] will generate name LIKE '%test%' AND name LIKE '%sample%'. The method will properly quote the column name and escape special characters in the values. Sometimes, you may want to add the percentage characters to the matching value by yourself, you may supply a third operand false to do so. For example, ['like', 'name', '%tester', false] will generate name LIKE '%tester'.
or like: similar to the like operator except that OR is used to concatenate the LIKE predicates when operand 2 is an array.
not like: similar to the like operator except that LIKE is replaced with NOT LIKE in the generated condition.
or not like: similar to the not like operator except that OR is used to concatenate the NOT LIKE predicates.
public function actionSearch($query)
{
$subqueries = preg_split("/\s/u", $query, -1, PREG_SPLIT_NO_EMPTY);
//Лучше потом отфильровать $subqueries убрав короткие слова или пошаманить с регуляркой что разбивало только если за пробелом слово больше n символов (чтоб Елизавета X так и осталась Елизавета X)
// например так
// $subqueries = preg_split("/\s(?=\w{2,})/u", $query, -1, PREG_SPLIT_NO_EMPTY)
$search = Serial::find()->where(['or',['like', 'name_serial', $subqueries],['like', 'description_serial', $subqueries]]);
$searchDataprovider = new ActiveDataProvider([
'query' => $search,
'pagination' => [
'pageSize' => 15,
],
]);
return $this->render('search', [
'searchDataprovider' => $searchDataprovider
]);
}
Есть компонент по типу gridview.
Весь js находится в vendor/component/panel
SomeGridWidget::widget([
'prop1'=>'val1',
'prop2'=>'val2',
'clientOptions'=>[
'onSomeEventCallback'=>new JsExpression('
function(callback_arguments){do_custom_behaviors();}
'),
]
]);
Но почему-то не видит методы find. Не могу понять, почему.
$result = [];
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
foreach($dataProvider->models as $model){
$result[$model->year][] = $model;
}
return $this->render('index', [
'searchModel' => $searchModel,
'result' => $result,
]);
<?php foreach($result as $year=>$models):?>
<h3><?=$year?></h3>
<?php foreach($models as $model):?>
<?=$model->data?>
<?php endforeach?>
<?php endforeach?>