【问题标题】:How concat two dropdownlist in php (Yii) and search concat results?如何在 php (Yii) 中连接两个下拉列表并搜索连接结果?
【发布时间】:2018-11-26 05:03:33
【问题描述】:

我刚刚学习 yii(一周),我有两个捕获月份和年份的下拉列表,但我需要使用连接的月份和年份并通过 submitButton 进行搜索,我该怎么做?

我的代码:

查看:

        <?php echo $form->dropDownList($model,'mes',CHtml::Listdata(Meses::model()->findAll(),'mesID','mesNom'), array('class'=>'form-control','prompt'=>'--Selección--')); ?>
        <?php echo $form->error($model,'fecha',array('class'=>'alert alert-danger')); ?>

        <?php echo $form->dropDownList($model,'anio',CHtml::Listdata(Anios::model()->findAll(),'anioID','anio'), array('class'=>'form-control','prompt'=>'--Selección--'));  ?>
        <?php echo $form->error($model,'anio',array('class'=>'alert alert-danger')); 
        ?>

    <?php echo CHtml::submitButton('Buscar', array('class'=>'btn btn-success')); ?>

如何在控制器中做到这一点? 请帮帮我。

【问题讨论】:

    标签: php html yii


    【解决方案1】:

    您可以通过从提交中获取值并过滤条件的数据依赖性来做到这一点,如下所示:

        public function actionYearMonthSearch()
            {   $month = 01; $year = 2018; // Default values
    
                // get values
                if(isset($_GET['month']))
                    $month= $_GET['month'];
    
                if(isset($_GET['year']))
                    $year=$_GET['year'];
    
                // You can concat both by $concat = $year.'-'.$month; and then using it nested of month and year like updated_at => $concat....etc
    
                $model = YourModel::model()->findAllByAttributes(array(
      'month' => $month,
       'year' => $year,
    ), array(
      'limit' => 5,
    ));
    
                // ... and any code you need too ...
            }
    

    您需要阅读Yii documentation 并查看actions,还有active record

    【讨论】:

    • 谢谢你:D(我很抱歉延迟回答)
    • 不客气 :) 如果你觉得它有帮助,我希望你接受答案 :) 谢谢 :D
    猜你喜欢
    • 2016-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    • 2014-05-14
    相关资源
    最近更新 更多