我在我的堆栈中注意到我的查询没有正确执行,因为我在querybuilder中有多个where子句.所以我在Yii Query构建器中查看了这个帖子Multiple call where
应用我读过的内容,但查询仍然没有结合where语句.我究竟做错了什么?
$command = Yii::app()->db->createCommand()
....
->where(array('in', 'u.id', $licenses), array('and', 'i.date_added > DATE_SUB(u.date_expired, INTERVAL 30 DAY)'));
//->where(array('and', 'i.date_added > DATE_SUB(u.date_expired, INTERVAL 30 DAY)'));
//->where(array('and', 'u.date_expired > CURDATE()'))
->group('u.id');
Run Code Online (Sandbox Code Playgroud)
这些是3个单独的陈述,但我在阅读时将它们合并,但结果仍然相同.只有1个where子句.
我为模型Faq生成了giix crud
控制器:
public function actionAdmin() {
$model = new Faq('search');
$model->unsetAttributes();
if (isset($_GET['Faq']))
$model->setAttributes($_GET['Faq']);
$this->render('admin', array(
'model' => $model,
));
}
Run Code Online (Sandbox Code Playgroud)
查看 - 管理员:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'faq-grid',
'dataProvider' => $model->search(array('order'=>'order ASC')),
'filter' => $model,
'columns' => array(
'order',
'question',
'answer',
array(
'class' => 'CButtonColumn',
),
),
)); ?>
Run Code Online (Sandbox Code Playgroud)
我想按字段"秩序"的项目,所以我添加
array('order'=>'order ASC')
到$model->search();但这并没有改变任何东西.哪里出错?
我目前正在尝试在Yii cGridview中实现自动过滤,默认情况下它会过滤'onclick'或'enter'按键,但我需要将该事件更改为"onkeyup"|
我的代码是这样的
Yii::app()->clientScript->registerScript('search',"
$('.filters > td >input').keyup(function(){
$('#grid-id').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
Run Code Online (Sandbox Code Playgroud)
当我输入第一个字母过滤发生,但过滤和渲染后代码失败..请给我一个解决方案..是否有任何PHP yii gridview扩展,其中有过滤onkeyup
尝试在x-editable中确定值时,我收到以下异常.[例外......""nsresult:"0x805e0006()"location:"JS frame :: :: .send :: line 8400"data:no]
View Code:
<?php $this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'subjectgrid',
'itemsCssClass' => 'table-bordered items',
'dataProvider' => new CActiveDataProvider('Examschedule',array(
'criteria'=>array('condition'=>"examcode=:newexam and sessioncode=:sessioncode",
'params'=>array(':newexam'=>$examcode, ':sessioncode'=>$sessioncode),),
'pagination'=>array('pageSize'=>15),)),
'columns'=>array(
array('name' => 'examcode', 'headerHtmlOptions' => array('style' => 'width: 10px'),),
array('name' => 'sessioncode', 'headerHtmlOptions' => array('style' => 'width: 10px'),),
array('name' => 'subjectcode', 'headerHtmlOptions' => array('style' => 'width: 10px'),),
array('name' => 'groupcode', 'headerHtmlOptions' => array('style' => 'width: 10px'), ),
array('class' => 'editable.EditableColumn', 'name' => 'dateofexam', 'headerHtmlOptions' => array('style' => 'width: 10px'), …Run Code Online (Sandbox Code Playgroud) 我正在开发Yii,我目前正在使用Yii twitter bootstrap用于在GridView中显示一些列:
假设我有这个:
$this->widget('bootstrap.widgets.TbGridView', array(
'id'=>'gridview',
'dataProvider'=>new CArrayDataProvider($model),
'template'=>"{items}",
'type'=>'bordered',
'columns'=>array(
array(
'header' => 'Entries',
'value' => '$data->entry_name'
),
array(
'name' => 'value',
'header' => 'Value',
'value'=>function($data){
//if $data->value is zero then hide the "Value" column
if($data->value == 0){
//do something to hide the column here
}
//otherwise return a label to display the value inside
return CHtml::label($data->value,FALSE,array('id'=>'label'));
},
'type'=>'raw',
),
)
)
);
Run Code Online (Sandbox Code Playgroud)
我可以使用以下方法隐藏整个列:
'headerHtmlOptions'=>array('style'=>'display:none'),
'htmlOptions'=>array('style'=>'display:none'),
Run Code Online (Sandbox Code Playgroud)
但这是在我将columns参数传递给小部件之后.我希望在值为零时隐藏"值"列.如何根据其值隐藏或显示整个列?非常感谢你!
嗨,我是yii的新手,我目前正在开展一个项目,我遇到了CDbCriteria问题.
我的目标查询是:
title LIKE '$_GET['search']%' OR description LIKE '$_GET['search']%'
Run Code Online (Sandbox Code Playgroud)
是否有可能使用CDbCriteria比较获得相同的结果?
控制器动作:
public function actionClassifieds(){
$model = new Classifieds('search');
$model->unsetAttributes();
if(isset($_GET['category'])){
if( $_GET['category'] == 0 ){
$model->classified_category_id = '';
}else{
$model->classified_category_id = $_GET['category'];
}
}
if(isset($_GET['search'])){
$model->title = $_GET['search'];
$model->description = $_GET['search'];
}
$this->render('classifieds',array('model'=>$model));
}
Run Code Online (Sandbox Code Playgroud)
我的模特:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('classified_category_id',$this->classified_category_id);
$criteria->compare('title',$this->title,true);
$criteria->compare('description',$this->description,true);
$criteria->compare('price',$this->price,true);
$criteria->compare('timestamp',$this->timestamp);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>10,
), …Run Code Online (Sandbox Code Playgroud) 我正在Yii中创建一个Web应用程序.我试图做一个sessiontimeout,如果用户闲置30分钟.之后他应该再次登录..但这不起作用.我正在使用CHttpSession.但是,如果我给CDbHttpSession而不是CHttpSession,这是正常的.
这是我的代码
'user' => array(
'class' => 'WebUser',
'loginUrl' => array('site/loginaccount'),
'allowAutoLogin' => true,
),
// uncomment the following to enable URLs in path-format
'session' => array(
'class'=>'CHttpSession',
'timeout'=>$params['session_timeout'],
'autoStart'=>true,
),
Run Code Online (Sandbox Code Playgroud)
还有什么可以让这个工作为CHttpSession?由于某些原因,我无法在我的Web应用程序中使用CDbHttpSession.
我正在使用yii,我想在cgridview中显示数组的结果Cgridview代码说
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'users-grid',
'dataProvider'=>$dataProviderObj,
//'filter'=>$model,
'columns'=>array(
'companyName',
array(
'header'=>'Products',
'value'=>'$data->usersproducts',
),
Run Code Online (Sandbox Code Playgroud)
现在,usersproducts是维护访问者和产品之间多对多关系的关系名称
一般来说,如果我想从$ data-> usersproducts获取数据, 我会这样做
foreach($data->usersproducts as $record)
{
echo $record->productName;
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在cgrid视图中获取此数据,因为foreach将无法在CGridView数组中工作?
我知道我可以使用($ this,functionName)并返回结果但我只想在数组中执行此操作.可能吗?如果是的话我怎么能这样做?
我是Yii的新人.
我的问题是在这个问题上.我有三个模块,它们都有一个默认的控制器我有以下网址:www.xxx.com/module/ 默认 /动作
我想有这个:www.xxx.com/module/action
请帮帮我,我无法弄清楚,虽然我已经阅读了很多关于它的主题,我不明白它们......
谢谢
addColumnCondition我使用函数,因为我喜欢它如何形成多个查询的查询.但我在文档中找不到任何改变它的比较操作,从简单= needle到a LIKE %needle%.有一个函数可以执行LIKE,addSearchCondition()但是它意味着获得相同的查询形成结果,我将不得不做一些循环和合并条件,如果有更好的解决方案,我想避免.
这是代码
foreach($query_set as $query){
foreach($attributes as $attribute=>$v){
$attributes[$attribute] = $query;
}
$criteria->addColumnCondition($attributes, 'OR', 'AND');
}
Run Code Online (Sandbox Code Playgroud)
而我正在形成像这样的条件
(business_name=:ycp0 OR payment_method=:ycp1) AND (business_name=:ycp2 OR payment_method=:ycp3)
Run Code Online (Sandbox Code Playgroud)
那么有没有办法配置使用的功能LIKE %:ycp0%而不是简单的=:ycp0.
任何帮助将不胜感激.
谢谢.