/**
* Created by PhpStorm.
* User: Andrey
* Date: 07.05.2016
* Time: 10:28
*/
namespace frontend\models;
use yii\db\ActiveRecord;
use frontend\models\Towar;
use Yii;
use yii\base\Model;
class OrderSearch extends Model
{
public $dwig;
public $priw;
public $kat;
public function rules()
{
return [
[['dwig', 'priw', 'kat'], 'required'],
];
}
public function scenarios()
{
return Model::scenarios(); // TODO: Change the autogenerated stub
}
/**
* @param $params
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Towar::find()
->where(['status' => Towar::STATUS_ACTIVE]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()){
return $dataProvider;
}
$query->andFilterWhere([
'dwig' => $this->dwig,
'priw' => $this->priw,
'kat' => $this->kat,
]);
return $dataProvider;
}
}
новая ошибка
Error
Undefined class constant 'STATUS_ACTIVE'
<img src="https://habrastorage.org/webt/60/a5/05/60a5056fc029d070893978.png" alt="image"/>
<?php
/**
* Created by PhpStorm.
* User: Andrey
* Date: 07.05.2016
* Time: 10:28
*/
namespace frontend\models;
use yii\db\ActiveRecord;
use frontend\models\Towar;
use Yii;
class OrderSearch extends Model
{
public $dwig;
public $priw;
public $kat;
public function rules()
{
return [
// необходимые правила валидации
];
}
public function scenarios()
{
return Model::scenarios(); // TODO: Change the autogenerated stub
}
/**
* @param $params
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Towar::find()
->where(['status' => Order::STATUS_ACTIVE]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()){
return $dataProvider;
}
$query->andFilterWhere([
'dwig' => $this->dwig,
'priw' => $this->priw,
'kat' => $this->kat,
]);
return $dataProvider;
}
}
выдаёт ошибку-
<img src="https://habrastorage.org/webt/60/a4/d9/60a4d928085ce625031687.png" alt="image"/>
public function actionIndex()
{
$model = new Product();
if ($model->load(Yii::$app->request->post())) {
if($model->price){
$price = $model->price;
$query = Product::find()->where(['price' => $price]);
}
}
return $this->render('index', compact('hits','pages','model'),[
'dataProvider' => $dataProvider,]);
$query = Product::find()->where(['>', 'price', $nahzap]);
$nahzap=600;
$query = Product::find()->where(['>', 'price', $nahzap]);
.public function actionIndex()
{
$model = new Product();
if ($model->load(Yii::$app->request->post())) {
if($model->nahzap){
$nahzap = [$model->nahzap];
$query = Product::find()->where(['>', 'price', $nahzap]);
}
}
То нет.
файл где находится форма main.php:
<code lang="php">
<?php $form = ActiveForm::begin(); ?>
echo $form->field($model, 'nahzap')->textInput(['maxlength' => true]) ;
ActiveForm::end();
</code>
$nahzap=600;
$query = Product::find()->where(['>', 'price', $nahzap]);
public function actionIndex()
{
$model = new Product();
if ($model->load(Yii::$app->request->post())) {
if($model->nahzap){
$nahzap = [$model->nahzap];
$query = Product::find()->where(['>', 'price', $nahzap]);
}
}
<?php $form = ActiveForm::begin(); ?>
echo $form->field($model, 'nahzap')->textInput(['maxlength' => true]) ;
ActiveForm::end();
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use backend\models\Teg;
use yii\helpers\ArrayHelper;
$data = Teg::find()->asArray()->all();
$data = ArrayHelper::getColumn($data, 'title');
echo $form->field($model, 'teg')->widget(Select2::classname(), [
'data' => $data,
'options' => ['placeholder' => 'Выберете тег ...'],
'pluginOptions' => [
'multiple' => true
],
]);