执行搜索后yii 1.x致命错误

时间:2015-04-17 16:29:54

标签: php yii

我必须采取行动执行similair功能。他们都有不同的观点,无论我在这两种观点上使用相同的_search.php观点。

这两项操作都有效,直到我开始使用advnaced搜索并在视图之间切换,我收到以下错误

Fatal error: CComponent::__call(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "LoggableBehavior" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /opt/yii-1.1.16.bca042/framework/base/CComponent.php on line 260

以下是错误操作

public function actionByuser()
    {   
        $obj = new GlobalController;
        $model=new Users('searchByUser');
        $model->unsetAttributes();  // clear any default values     
        $modelClass = "Users";
        if (intval(Yii::app()->request->getParam('clearFilters'))==1) {
            EButtonColumnWithClearFilters::clearFilters($this,$model);//where $this is the controller
        }


        //Yii::log(print_r($_GET,true));
        if(isset($_GET['Users'])){
            $model->attributes=$_GET['Users'];
            Yii::app()->user->setState($this->id . 'Users-state', $model);
            Yii::log(print_r($_GET['Users'],true));
        }elseif(Yii::app()->user->getState($this->id . 'Users-state')){
            Yii::log(print_r(Yii::app()->user->getState($this->id . 'Users-state')->attributes,true));
            $model = Yii::app()->user->getState($this->id . 'Users-state');

        }

        $pageParam = ucfirst($modelClass) . '_page';
        if (isset($_GET[$pageParam])) {
            $page = $_GET[$pageParam];
            Yii::app()->user->setState($this->id . 'Users_page', (int) $page);

        }elseif(count($_GET) >= 3 && !isset($_GET['Users_page'])){
            $_GET[$pageParam] = 1;
            Yii::app()->user->setState($this->id . 'Users_page', 1);

        }else{
            $page = Yii::app()->user->getState($this->id . 'Users_page', 1);
            $_GET[$pageParam] = $page;
        }

        if (isset($_GET[ucfirst($this->id) .'Users_sort'])) {
            $extractSort = $_GET[ucfirst($this->id) .'Users_sort'];
            Yii::app()->user->setState(ucfirst($this->id) .'Users_sort', $extractSort);
        } else if (isset($_GET['sort'])) {
            $extractSort = $_GET['sort'];
            Yii::app()->user->setState(ucfirst($this->id) .'Users_sort', $extractSort);
        } else if(Yii::app()->user->hasState(ucfirst($this->id) .'Users_sort')) {
            $_GET['sort'] = Yii::app()->user->getState(ucfirst($this->id) .'Users_sort');
        }

        if(isset($_GET['Users'])){
            $model->attributes=$_GET['Users'];
            Yii::log(print_r($_GET['Users'],true));

            //check if all values are null
            $empty = true;
            foreach ($_GET['Users'] as $key => $value) {
                if(!empty($value))
                    $empty = false;
            }
            if($empty){
                $_GET = array_shift($_GET);
                Yii::app()->user->setState('ProjectcostsUsersParams', array('notempty'));
            }else{
                Yii::app()->user->setState('ProjectcostsUsersParams', $_GET['Users']);
                Yii::app()->user->setState($this->id . 'Users-state', $model);
            }           

        }elseif(Yii::app()->user->getState($this->id . 'Users-state')){
            $model = Yii::app()->user->getState($this->id . 'Users-state');             
        }else
            Yii::app()->user->setState('ProjectcostsUsersParams', array('notempty'));       

        $usersList = $obj->getProcessorList();
        $projCodeList = $obj->getProjectcodeList(array("condition"=>"projectcode NOT IN ('A','B','G','M','O','P','S')"));
        $mcList = array('MC' => "MC","P"=>"Propietary");

        $this->render('byuser',array(
            'model'=>$model,
            'usersList'=>$usersList,
            'projCodeList'=>$projCodeList,
            'mcList'=>$mcList
        ));Yii::log($this->id);
    }

这是视图

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
    $('.search-form').toggle();
    return false;
});
$('.search-form form').submit(function(){
    $('#projectcosts-byuser-grid').yiiGridView('update', {
        data: $(this).serialize()
    });
    return false;
});
");
?>

<h1>Manage Man Hours</h1>

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
        'model'=>$model,
        'usersList'=>$usersList,
        'projCodeList'=>$projCodeList,
        'mcList'=>$mcList,
        "modelName"=>"Users"
)); ?>
</div><!-- search-form -->

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'projectcosts-byuser-grid',
    'dataProvider'=>$model->searchByUser(),
    'filter'=>$model,
    'rowCssClassExpression'=>'($data->ACTIVE != 0) ? ($row%2?"even":"odd") : "red" ',
    'columns'=>array(
        'name',
        'totalunits',
        array(
            'header'=>'Expected Hours',
            'value'=>'$data->getExpectedHours()',
        ),
        array(
            'class'=>'EButtonColumnWithClearFilters',
            'template'=>'',
            'onClick_BeforeClear'=>'if(!confirm("This will reset all values"))
                                        return false;
                $.ajax({
                    url: "index.php?r=Projectcosts/unsetStateUsers",
                    success:function(data){},
                    error: function (request, status, error) {}
                })',
            'url'=>'Yii::app()->controller->createUrl("unsetStateUsers",array("clearFilters"=>1))',
        ),
    ),
)); ?>

共享的search文件

Yii::app()->clientScript->registerScript('daterangescript-'.$modelName,"
    var dates = $('#".$modelName."_DATE_0, #".$modelName."_DATE_1').datepicker({
        //defaultDate: '+1w',
        changeMonth: true,
        changeYear: true,
        numberOfMonths: 1,
        onSelect: function( selectedDate ) {
        }
    });

    $('#".$modelName."_DATE_0, #".$modelName."_DATE_1').datepicker('option', 'dateFormat', 'yy-mm-dd');
",CClientScript::POS_READY);
?>

<div class="wide form">

<?php $form=$this->beginWidget('CActiveForm', array(
    'action'=>Yii::app()->createUrl($this->route),
    'method'=>'get',
)); ?>

    <div class="row">
        <?php echo $form->label($model,'project'); ?>
        <?php 
        $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
                'name'=>'Users[project]',
                'attribute'=>'project',
                'sourceUrl'=>array('Projects/ProjectsNameList'),
                'model'=>$model,
                'options'=>array(
                        'minLength'=>'5',
                ),
                'htmlOptions'=>array(
                        'size'=>50,
                        'maxlength'=>50,
                ),
        ));
        ?>
    </div>

    <div class="row">
        <?php echo $form->label($model,'PROJCODE'); ?>
        <?php echo "<table id=Search_Office_chkbx><tr>".CHtml::activecheckboxlist($model,'PROJCODE',$projCodeList,array('separator'=>'','template'=>'<td>{label} {input}</td>')) . "</tr></table>"; ?>
    </div>

    <div class="row">
        <label>MC or Propietary</label> 
        <?php echo $form->dropDownList($model,'MC',$mcList,array('prompt' => '-- Select--'));?><span style="color:red;font-size:10px;margin-left:20px;font-style: italic;">(Leave blank for both)</span>        
    </div>

    <div class="row">
        <?php echo $form->label($model,'DATE'); ?>
        <?php //echo $form->textField($model,'DATE'); 
        $attribute = 'DATE';
        for ($i = 0; $i <= 1; $i++)
        {
        echo ($i == 0 ? Yii::t('main', 'From/After:') : Yii::t('main', 'To/Before:'));
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                'id'=>CHtml::activeId($model, $attribute.'_'.$i),
                'model'=>$model,
                'attribute'=>$attribute."[$i]",
                'options'=>array(
                        'showAnim'=>'fold',
                        'dateFormat'=>'yy-mm-dd',
                    ),
                        'htmlOptions'=>array(
                                'size'=>9,
                                'maxlength'=>10,
                        ),
                ));
        }       
        ?>
    </div>

    <div class="row" id="man_hours_OFFICE">
        <div style="display:inline-block">
            <?php echo $form->label($model,'OFFICE');?>
            <select id="<?=$modelName?>_OFFICE" name="<?=$modelName?>[OFFICE]" onchange="site_change();">
                <option value="">-- Select--</option>
                <option value="Brazil">Brasil</option>
                <option value="Egypt">Cairo</option>
                <option value="Houston">Houston</option>
                <option value="ASB">Jakarta</option>
                <option value="ASA">Oslo</option>
                <option value="UK">Woking</option>
            </select>
        </div>      
    </div>


    <div class="row" id="man_hours_site">
        <div style="display:inline-block">
            <?php echo $form->label($model,'site');?>
            <select id="<?=$modelName?>_site" name="<?=$modelName?>[site]" onchange="site_change();">
                <option value="">-- Select--</option>
                <option value="cairo">Cairo</option>
                <option value="houston">Houston</option>
                <option value="jakarta">Jakarta</option>
                <option value="woking">Woking</option>
            </select>
        </div>
        <div style="display:inline-block;" id="Projectcosts_PR_container">
        </div>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton('Search'); ?>
    </div>

<?php $this->endWidget(); ?>

序列化更新 我已更新它以序列化属性,但它似乎没有在会话中保存值?

public function actionByuser()
    {   
        $obj = new GlobalController;
        $model=new Users('searchByUser');
        $model->unsetAttributes();  // clear any default values     
        $modelClass = "Users";
        if (intval(Yii::app()->request->getParam('clearFilters'))==1) {
            EButtonColumnWithClearFilters::clearFilters($this,$model);//where $this is the controller
    }

        if(isset($_GET['Users'])){
            $model->attributes=$_GET['Users'];
            Yii::app()->user->setState($this->id . 'Users-state', serialize($model->attributes));

        }elseif(Yii::app()->user->getState($this->id . 'Users-state')){

            $model->attributes = unserialize(Yii::app()->user->getState($this->id . 'Users-state'));
        }

        $pageParam = ucfirst($modelClass) . '_page';
        if (isset($_GET[$pageParam])) {
            $page = $_GET[$pageParam];
            Yii::app()->user->setState($this->id . 'Users_page', (int) $page);

        }elseif(count($_GET) >= 3 && !isset($_GET['Users_page'])){
            $_GET[$pageParam] = 1;
            Yii::app()->user->setState($this->id . 'Users_page', 1);

        }else{
            $page = Yii::app()->user->getState($this->id . 'Users_page', 1);
            $_GET[$pageParam] = $page;

        }

        if (isset($_GET[ucfirst($this->id) .'Users_sort'])) {
            $extractSort = $_GET[ucfirst($this->id) .'Users_sort'];

            Yii::app()->user->setState(ucfirst($this->id) .'Users_sort', $extractSort);
        } else if (isset($_GET['sort'])) {
            $extractSort = $_GET['sort'];

            Yii::app()->user->setState(ucfirst($this->id) .'Users_sort', $extractSort);
        } else if(Yii::app()->user->hasState(ucfirst($this->id) .'Users_sort')) {
            $_GET['sort'] = Yii::app()->user->getState(ucfirst($this->id) .'Users_sort');

        }

        if(isset($_GET['Users'])){
            $model->attributes=$_GET['Users'];

            //check if all values are null
            $empty = true;
            foreach ($_GET['Users'] as $key => $value) {
                if(!empty($value))
                    $empty = false;
            }
            if($empty){
                $_GET = array_shift($_GET);
                Yii::app()->user->setState('ProjectcostsUsersParams', array('notempty'));
            }else{
                Yii::app()->user->setState('ProjectcostsUsersParams', $_GET['Users']);
                Yii::app()->user->setState($this->id . 'Users-state', serialize($model->attributes));
            }           

        }elseif(Yii::app()->user->getState($this->id . 'Users-state')){

            $model->attributes = unserialize(Yii::app()->user->getState($this->id . 'Users-state'));

        }else
            Yii::app()->user->setState('ProjectcostsUsersParams', array('notempty'));   

        $usersList = $obj->getProcessorList();
        $projCodeList = $obj->getProjectcodeList(array("condition"=>"projectcode NOT IN ('A','B','G','M','O','P','S')"));
        $mcList = array('MC' => "MC","P"=>"Propietary");

        $this->render('byuser',array(
            'model'=>$model,
            'usersList'=>$usersList,
            'projCodeList'=>$projCodeList,
            'mcList'=>$mcList
        ));
    }

下面是序列化并设置后直接记录

Yii::log(print_r(unserialize(Yii::app()->user->getState($this->id . 'Users-state')),true));

Array
(
    [ACTIVE] => 
    [user_id] => 
    [PROC] => 
    [name] => 
    [LEVEL] => 
    [EMAIL] => 
    [TITLE] => 
    [site] => 
    [objectSid] => 
    [last_login] => 
)

以下是获取请求的日志

Yii::log(print_r($_GET['Users'],true));
 Array
(
    [project] => 
    [PROJCODE] => Array
        (
            [0] => W
        )

    [MC] => 
    [DATE] => Array
        (
            [0] => 
            [1] => 
        )

    [OFFICE] => 
    [site] => 
)

看起来它只使用Model-&gt;属性来获取数据库列而不是类中的派生列。

我现在面临的问题是它不是应用搜索参数

public function actionByuser()
    {   
        $obj = new GlobalController;
        $model=new Users('searchByUser');
        $model->unsetAttributes();  // clear any default values     
        $modelClass = "Users";

        if (intval(Yii::app()->request->getParam('clearFilters'))==1) {
            EButtonColumnWithClearFilters::clearFilters($this,$model);//where $this is the controller

        }

        if(isset($_GET['Users'])){
            $model->attributes=$_GET['Users'];
            Yii::app()->user->setState($this->id . 'Users-state', serialize($_GET['Users']));
                        }elseif(Yii::app()->user->getState($this->id . 'Users-state')){
                            $model->attributes = unserialize(Yii::app()->user->getState($this->id . 'Users-state'));
        }

        $pageParam = ucfirst($modelClass) . '_page';
        if (isset($_GET[$pageParam])) {
            $page = $_GET[$pageParam];
            Yii::app()->user->setState($this->id . 'Users_page', (int) $page);

        }elseif(count($_GET) >= 3 && !isset($_GET['Users_page'])){
            $_GET[$pageParam] = 1;
            Yii::app()->user->setState($this->id . 'Users_page', 1);

        }else{
            $page = Yii::app()->user->getState($this->id . 'Users_page', 1);
            $_GET[$pageParam] = $page;

        }

        if (isset($_GET[ucfirst($this->id) .'Users_sort'])) {
            $extractSort = $_GET[ucfirst($this->id) .'Users_sort'];

            Yii::app()->user->setState(ucfirst($this->id) .'Users_sort', $extractSort);
        } else if (isset($_GET['sort'])) {
            $extractSort = $_GET['sort'];

            Yii::app()->user->setState(ucfirst($this->id) .'Users_sort', $extractSort);
        } else if(Yii::app()->user->hasState(ucfirst($this->id) .'Users_sort')) {
            $_GET['sort'] = Yii::app()->user->getState(ucfirst($this->id) .'Users_sort');

        }

        if(isset($_GET['Users'])){
            $model->attributes=$_GET['Users'];

            //check if all values are null
            $empty = true;
            foreach ($_GET['Users'] as $key => $value) {
                if(!empty($value))
                    $empty = false;
            }
            if($empty){
                $_GET = array_shift($_GET);
                Yii::app()->user->setState('ProjectcostsUsersParams', array('notempty'));
            }else{
                Yii::app()->user->setState('ProjectcostsUsersParams', $_GET['Users']);
                Yii::app()->user->setState($this->id . 'Users-state', serialize($_GET['Users']));
            }           

        }elseif(Yii::app()->user->getState($this->id . 'Users-state')){
            Yii::log(print_r(unserialize(Yii::app()->user->getState($this->id . 'Users-state')),true));
            $model->attributes = unserialize(Yii::app()->user->getState($this->id . 'Users-state'));
            //Yii::log(print_r($_GET['Projectcosts']=Yii::app()->user->getState('ProjectcostsParams'),true));

        }else
            Yii::app()->user->setState('ProjectcostsUsersParams', array('notempty'));   

        //Yii::log($this->id);
        $usersList = $obj->getProcessorList();
        $projCodeList = $obj->getProjectcodeList(array("condition"=>"projectcode NOT IN ('A','B','G','M','O','P','S')"));
        $mcList = array('MC' => "MC","P"=>"Propietary");

        //Yii::log($this->id);
        $this->render('byuser',array(
            'model'=>$model,
            'usersList'=>$usersList,
            'projCodeList'=>$projCodeList,
            'mcList'=>$mcList
        ));Yii::log($this->id);
    }

这是我的第二个动作,它是使用不同州名的similair。

public function actionByproject()
    {
        $obj = new GlobalController;
        $model=new Projectcosts('searchByProject');
        $model->unsetAttributes();  // clear any default values
        //Yii::log(print_r($_GET,true));
        if (intval(Yii::app()->request->getParam('clearFilters'))==1) {
            EButtonColumnWithClearFilters::clearFilters($this,$model);//where $this is the controller
            //Yii::log(Yii::app()->request->getParam('clearFilters'));
        }

        //Yii::log($this->id);
        if(isset($_GET['Projectcosts'])){
            $model->attributes=$_GET['Projectcosts'];
            Yii::app()->user->setState($this->id . '-state', $model);

        }elseif(Yii::app()->user->getState($this->id . '-state')){
            Yii::log(print_r(Yii::app()->user->getState($this->id . '-state')->attributes,true));
            $model = Yii::app()->user->getState($this->id . '-state');

        }

        $pageParam = ucfirst($this->modelClass) . '_page';
        if (isset($_GET[$pageParam])) {
            $page = $_GET[$pageParam];
            Yii::app()->user->setState($this->id . '_page', (int) $page);

        }elseif( count($_GET) == 2 || count($_GET) == 3 || count($_GET) == 4 ){
            $_GET[$pageParam] = 1;          
            Yii::app()->user->setState($this->id . '_page', 1);
        }else{
            $page = Yii::app()->user->getState($this->id . '_page', 1);
            $_GET[$pageParam] = $page;

        }

        //ViewWebprojectreport_sort
        //Yii::log(ucfirst($this->id) .'_sort');
        if (isset($_GET[ucfirst($this->id) .'_sort'])) {
            $extractSort = $_GET[ucfirst($this->id) .'_sort'];
            //Yii::log($extractSort);
            Yii::app()->user->setState(ucfirst($this->id) .'_sort', $extractSort);
        } else if (isset($_GET['sort'])) {
            $extractSort = $_GET['sort'];
            //Yii::log($extractSort);
            Yii::app()->user->setState(ucfirst($this->id) .'_sort', $extractSort);
        } else if(Yii::app()->user->hasState(ucfirst($this->id) .'_sort')) {
            $_GET['sort'] = Yii::app()->user->getState(ucfirst($this->id) .'_sort');
            //Yii::log(Yii::app()->user->getState(ucfirst($this->id) .'_sort'));
        }
        //Yii::log($this->id);

        if(isset($_GET['Projectcosts'])){
            $model->attributes=$_GET['Projectcosts'];
            Yii::log(print_r($_GET['Projectcosts'],true));

            //check if all values are null
            $empty = true;
            foreach ($_GET['Projectcosts'] as $key => $value) {
                if(!empty($value))
                    $empty = false;
            }
            if($empty){
                $_GET = array_shift($_GET);
                Yii::app()->user->setState("ProjectcostsParams", array('notempty'));
            }else{
                Yii::app()->user->setState("ProjectcostsParams", $_GET['Projectcosts']);
                Yii::app()->user->setState($this->id . '-state', $model);
            }

        }elseif(Yii::app()->user->getState($this->id . '-state')){
            //Yii::log("STATE EXISTS",CLogger::LEVEL_INFO, __METHOD__);
            $model = Yii::app()->user->getState($this->id . '-state');
            //Yii::log(print_r($_GET['Projectcosts']=Yii::app()->user->getState('ProjectcostsParams'),true));

        }else
            Yii::app()->user->setState("ProjectcostsParams", array('notempty'));


        $usersList = $obj->getProcessorList();
        $projCodeList = $obj->getProjectcodeList(array("condition"=>"projectcode NOT IN ('A','B','G','M','O','P','S')"));
        $mcList = array('MC' => "MC","P"=>"Propietary");


        $this->render('byproject',array(
                'model'=>$model,
                'usersList'=>$usersList,
                'projCodeList'=>$projCodeList,
                'mcList'=>$mcList
        ));
    }

我必须稍微更改模型搜索功能以检查状态并包含搜索条件。这是正确的做法吗?

public function searchByUser($filter = array())
    {
        // @todo Please modify the following code to remove attributes that should not be searched.

        $formatter = Yii::app()->getDateFormatter();
        $format = 'yyy-MM-d';

        $criteria=new CDbCriteria;
        $criteria->select = 't.*,
                            PROJECT AS project,
                            round(sum(UNITS),2) AS totalunits,
                            round(sum(COST),2) AS totalcost,
                            min(DATE) as firstupdated,
                            max(DATE) as lastupdated,
                            PROJCODE AS PROJCODE,
                            (case NES
                                when -(1) then _utf8"MC"
                                when 0 then _utf8"P"
                                when 1 then _utf8"MC"
                            end) AS `MC`,
                            DATE AS DATE,
                            OFFICE AS OFFICE';

        $criteria->compare('name',$this->name,true);
        //$criteria->compare('LEVEL',$this->LEVEL);
        $criteria->compare('EMAIL',$this->EMAIL,true);
        $criteria->compare('ACTIVE',$this->ACTIVE);
        $criteria->compare('job_title.desc',$this->TITLE,true);
        $criteria->compare('site',$this->site,true);



        //adv search form
        if( (isset($_GET['Users']['PROJCODE']) && !empty($_GET['Users']['PROJCODE']) ) || (!empty($filter) && isset($filter['Users']) ) ){
            $this->PROJCODE = (!empty($_GET['Users']['PROJCODE'])) ? $_GET['Users']['PROJCODE'] : $filter['PROJCODE'];
            $criteria->compare('PROJCODE',$this->PROJCODE);
        }

        if( (isset($_GET['Users']['OFFICE']) && !empty($_GET['Users']['OFFICE']) ) || (!empty($filter) && isset($filter['OFFICE']) ) ){
            $this->OFFICE = (!empty($_GET['Users']['OFFICE'])) ? $_GET['Users']['OFFICE'] : $filter['OFFICE'];
            $criteria->compare('OFFICE',$this->OFFICE);
        }

        $criteria->mergeWith($this->dateRangeSearchCriteria('DATE', $this->DATE));
        if( ($filter && isset($filter['DATE'])) || (isset($_GET['Users']['DATE']) && !empty($_GET['Users']['DATE'])) ){
            $date = (!empty($_GET['Users']['DATE'])) ? $_GET['Users']['DATE'] : $filter['DATE'];
            $criteria->mergeWith($this->dateRangeSearchCriteria('DATE', $date) );
        }

        if( (isset($_GET['Users']['project']) && !empty($_GET['Users']['project']) ) || (!empty($filter) && isset($filter['project']) ) ){
            $this->project = (!empty($_GET['Users']['project'])) ? $_GET['Users']['project'] : $filter['project'];
            $criteria->compare('project',$this->project,true);
        }


        if( (Yii::app()->user->getState('projectcostsUsers-state')) ){
            $params = Yii::app()->user->getState('projectcostsUsers-state');
            foreach ($params as $key => $value) {
                if(!empty($value) && !is_array($value))
                    $criteria->compare($key,$this->$value);

                elseif(is_array($value) && $key == "DATE")
                    $criteria->mergeWith($this->dateRangeSearchCriteria('DATE', $value) );

                elseif(is_array($value) && $key == "PROJCODE")
                    $criteria->addInCondition("PROJCODE", array(implode(",", $value)));
            }
        }


        //model search grid
        if(isset($_GET['Users']['totalunits']) && !empty($_GET['Users']['totalunits'])){
            //preg_match( '/[0-9]*/', $_GET['Users']['totalunits'], $match );
            $match = preg_replace("/[^0-9]/","",$_GET['Users']['totalunits']);//filter_var($_GET['Users']['totalunits'], FILTER_SANITIZE_NUMBER_INT);
            preg_match( '/[>=<]*/', $_GET['Users']['totalunits'], $operand );

            $operand = (!empty($operand[0])) ? $operand[0] : "=";
            //Yii::log(print_r($match,true));
            //print_r($match);
            //exit();
            $criteria->having = 'totalunits '.$operand.' '.$match.'';
        }

        $criteria->join = 'left join projectcosts on PR = user_id';
        $criteria->join .= ' left join projects on projects.PROJID = projectcosts.PROJID';


        //Yii::log(print_r($_GET,true));
        //Yii::log(print_r($filter,true));
        //initial load 
        if( !isset($_GET['ajax']) || 
                count($_GET) == 2 || 
                count($_GET) == 3 || 
                 ( count($_GET) >= 3 && ( !isset($_GET['sort'])  ) )  ){            
            //$criteria->addInCondition('ACTIVE',array(-1,1));
            $criteria->order ='name';
        }
        $criteria->addInCondition('ACTIVE',array(-1,1));

        //dp users only
        $criteria->addInCondition('t.LEVEL',array(1,3,4,5));


        $criteria->group='user_id';

        $sort=new CSort;
        $sort->attributes=array(
                'name',             
                'totalunits'=>array(
                        'asc'=>'totalunits asc',
                        'desc'=>'totalunits desc',
                ),
        );


        return new CActiveDataProvider($this, array(
                'criteria'=>$criteria,
                'pagination'=>array(
                        'pageSize'=>25,
                ),
                'sort'=>$sort
        ));
    }

更新了控制器操作

public function actionByuser()
    {   
        $obj = new GlobalController;
        $model=new Users('searchByUser');
        $model->unsetAttributes();  // clear any default values     
        $modelClass = "Users";

        if (intval(Yii::app()->request->getParam('clearFilters'))==1) {
            EButtonColumnWithClearFilters::clearFilters($this,$model);//where $this is the controller
            //Yii::log(Yii::app()->request->getParam('clearFilters'));
        }

        if(isset($_GET['Users'])){
            $model->attributes=$_GET['Users'];
            Yii::app()->user->setState($this->id . 'Users-state', $_GET['Users']);

            $empty = true;
            foreach ($_GET['Users'] as $key => $value) {
                if(!empty($value))
                    $empty = false;
            }
            if($empty){
                $_GET = array_shift($_GET);
                Yii::app()->user->setState('ProjectcostsUsersParams', array('notempty'));
                Yii::app()->user->setState($this->id . 'Users-state', null);
            }else{
                Yii::app()->user->setState('ProjectcostsUsersParams', $_GET['Users']);
                //Yii::app()->user->setState($this->id . 'Users-state', $_GET['Users']);
            }

        }

        $pageParam = ucfirst($modelClass) . '_page';
        if (isset($_GET[$pageParam])) {
            $page = $_GET[$pageParam];
            Yii::app()->user->setState($this->id . 'Users_page', (int) $page);

        }elseif(count($_GET) >= 3 && !isset($_GET['Users_page'])){
            $_GET[$pageParam] = 1;
            Yii::app()->user->setState($this->id . 'Users_page', 1);

        }else{
            $page = Yii::app()->user->getState($this->id . 'Users_page', 1);
            $_GET[$pageParam] = $page;
            //Yii::log($this->id);
        }

        //ViewWebprojectreport_sort
        //Yii::log(ucfirst($this->id) .'_sort');
        if (isset($_GET[ucfirst($this->id) .'Users_sort'])) {
            $extractSort = $_GET[ucfirst($this->id) .'Users_sort'];
            //Yii::log($extractSort);
            Yii::app()->user->setState(ucfirst($this->id) .'Users_sort', $extractSort);
        } else if (isset($_GET['sort'])) {
            $extractSort = $_GET['sort'];
            //Yii::log($extractSort);
            Yii::app()->user->setState(ucfirst($this->id) .'Users_sort', $extractSort);
        } else if(Yii::app()->user->hasState(ucfirst($this->id) .'Users_sort')) {
            $_GET['sort'] = Yii::app()->user->getState(ucfirst($this->id) .'Users_sort');
            //Yii::log(Yii::app()->user->getState(ucfirst($this->id) .'_sort'));
        }

        //Yii::log($this->id);
        $usersList = $obj->getProcessorList();
        $projCodeList = $obj->getProjectcodeList(array("condition"=>"projectcode NOT IN ('A','B','G','M','O','P','S')"));
        $mcList = array('MC' => "MC","P"=>"Propietary");

        //Yii::log(print_r($model,true));
        $this->render('byuser',array(
            'model'=>$model,
            'usersList'=>$usersList,
            'projCodeList'=>$projCodeList,
            'mcList'=>$mcList
        ));
    }

0 个答案:

没有答案