0

我从 CActiveDataProvider 获取空数组,而(属性)totalItemCount 返回 2。

我的配置中有'enableParamLogging'=>true,并启用了CWebLogRoute。当我通过 CActiveDataProvider 执行生成的查询时,我得到 2 行,但 CActiveDataProvider->data 返回一个空数组。

基本上它是一个安装了扩展的Employee <-> Shift Roaster编辑bootstrapx-editable

模型

public function relations()
{
    return array(
        'rstEmp' => array(self::BELONGS_TO, 'Employee', 'RstEmpId'),
    );
}
public function getNew($depId){
    $criteria=new CDbCriteria;
    $criteria->with = array(
        'rstEmp' => array(
            'select'    =>  'EmpId, EmpFirstName, EmpLastName',
            'condition' =>  'EmpDepId='.$depId.' AND EmpRoaster=1 ',
            'joinType'  =>  'RIGHT JOIN',
            'on'        =>  'RstId='.$this->RstId,
        )
    );
    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
    ));
}

控制器

public function actionUpdate($id)
{
    $this->layout='//layouts/column1';
    $model=$this->loadModel($id);
    $roaster=new Roaster;
    $roaster->RstId=$id;
    $this->render('update',array(
        'model'=>$model,
        'roaster'=>$roaster,
    ));
}

看法

$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'usergrid',
'itemsCssClass' => 'table-bordered items',
'dataProvider' => $roaster->getNew($model->RoasterDepId),
'columns'=>array(
    'RstEmpId',
    array(
       'name' => 'RstEmpId',
       'value'=>'$data->rstEmp->EmpFirstName." ".$data->rstEmp->EmpLastName ',
    ),
    array( 
          'class' => 'editable.EditableColumn',
          'name' => 'd01',
          'editable' => array(
              'type'     => 'select',
              'url'      => $this->createUrl('Roasters/addRoasterEmployee'),
              'source'   => $this->createUrl('getShifts', array('id'=>$roaster->RstId)),
          )
    ),
),

));

生成的查询

SELECT TOP 10 
[t].[RstId] AS [t0_c0], 
[t].[RstEmpId] AS [t0_c1], 
[t].[d01] AS [t0_c2], 
[rstEmp].[EmpId] AS [t1_c0], 
[rstEmp].[EmpFirstName] AS [t1_c1], 
[rstEmp].[EmpLastName] AS [t1_c2] 
FROM [rehman].[Roaster] [t]  RIGHT JOIN [rehman].[Employee] [rstEmp] 
ON ([t].[RstEmpId]=[rstEmp].[EmpId]) AND (RstId=2)  
WHERE (EmpDepId=2 AND EmpRoaster=1 )

结果

在此处输入图像描述

print_r($roaster->getNew($model->RoasterDepId))给出以下结果

CActiveDataProvider Object
(
[modelClass] => Roaster
[model] => Roaster Object
    (
        [shifts] => Array
            (
            )

        [_new:CActiveRecord:private] => 1
        [_attributes:CActiveRecord:private] => Array
            (
                [RstId] => 2
            )

        [_related:CActiveRecord:private] => Array
            (
            )

        [_c:CActiveRecord:private] => 
        [_pk:CActiveRecord:private] => 
        [_alias:CActiveRecord:private] => t
        [_errors:CModel:private] => Array
            (
            )

        [_validators:CModel:private] => 
        [_scenario:CModel:private] => insert
        [_e:CComponent:private] => 
        [_m:CComponent:private] => 
    )

[keyAttribute] => 
[_criteria:CActiveDataProvider:private] => CDbCriteria Object
    (
        [select] => *
        [distinct] => 
        [condition] => 
        [params] => Array
            (
            )

        [limit] => -1
        [offset] => -1
        [order] => 
        [group] => 
        [join] => 
        [having] => 
        [with] => Array
            (
                [rstEmp] => Array
                    (
                        [select] => EmpId, EmpFirstName, EmpLastName
                        [condition] => EmpDepId=2 AND EmpRoaster=1 
                        [joinType] => RIGHT JOIN
                        [on] => RstId=2
                    )

            )

        [alias] => 
        [together] => 
        [index] => 
        [scopes] => 
        [_e:CComponent:private] => 
        [_m:CComponent:private] => 
    )

[_countCriteria:CActiveDataProvider:private] => 
[_id:CDataProvider:private] => Roaster
[_data:CDataProvider:private] => 
[_keys:CDataProvider:private] => 
[_totalItemCount:CDataProvider:private] => 
[_sort:CDataProvider:private] => 
[_pagination:CDataProvider:private] => 
[_e:CComponent:private] => 
[_m:CComponent:private] => 
)

提前致谢

4

0 回答 0