gpt4 book ai didi

php - 不符合条件 无法在 Yii2 中工作

转载 作者:行者123 更新时间:2023-11-29 18:32:51 26 4
gpt4 key购买 nike

我把它清理了一下,所以问题是为什么当我说不的时候 searchmodel 返回 id=30 的房间
搜索模型代码

public function search($params)
{
$ids = [];
$ids[]=30;
$query = room::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {

}
$query->andFilterWhere([
'price' => $this->price,
'category_id' => $this->category_id,
'id' => $this->id,
'ci_id'=>$this->ci_id;

]);
$query->andFilterWhere(['not in','id',$ids]);
return $dataProvider;
}

这里的 Controller 操作是 Controller 操作,我不认为有什么奇怪的,只是发布以防万一出现问题。

public function actionIndex()
{
$searchModel = new roomSearch();
//$user = Yii::$app->user->identity;

if ($searchModel->load(Yii::$app->request->post()) ) {
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
else{

//

$dataProvider = $searchModel->search(Yii::$app->request->queryParams);


return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
}

显示房间的查看代码如下:

  <?php \yii\widgets\Pjax::begin(['timeout' => 30000, 'clientOptions' => ['container' => 'pjax-container']]); 
?>

<?php $form = ActiveForm::begin([ 'action' => ['index'],
'method' => 'get','options' => ['data-pjax' => true ],]); ?>
<?= $form->field($searchModel, 'category_id')->dropdownList(MtCat::getHierarchy(false, [], false, false),['onchange'=>'this.form.submit()','prompt' => 'Όλες οι κατηγορίες']); ?>
<?= $form->field($searchModel, 'ci_id')->dropdownList(City::getList(),['onchange'=>'this.form.submit()','prompt' => 'Όλες οι περιοχές']); ?>

<?php ActiveForm::end(); ?>
</br>


<?=

ListView::widget([

'layout' => "{pager}\n{summary}\n<div class='all-items'>{items}</div>\n{pager}",

//'layout' => "{pager}\n<div class='all-items'>{items}</div>\n{pager}",

'summary' => sprintf('<div class="summary"><b>%s</b> αποτελέσματα δωματίων</div>', $dataProvider->totalCount),

'dataProvider' => $dataProvider,

'showOnEmpty' => false,


'itemOptions' => ['class' => 'item'],

'itemView' => '_img', /* function ($model, $key, $index, $widget) { return Html::a(Html::encode($model->id), ['view', 'id' => $model->id]); }, */

'pager' => [

'maxButtonCount' => ceil($dataProvider->totalCount / $dataProvider->pagination->pageSize),

],

]);

?>
<?php \yii\widgets\Pjax::end(); ?>

最佳答案

原因是您只选择了

room_id

这就是为什么它看不到

id

您可以像这样更改代码的前几行。

$ids = [];
$ids[] = 30;
$results = Yii::$app->db->createCommand('select id,room_id from y2gall_reservations')->queryAll();
$query = room::find();

关于php - 不符合条件 无法在 Yii2 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45548336/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com