0

$criteria->with=array('profile');フィールドを追加すると、revent_datetime常にNULLが返されますがwithrevent_datetime戻り権はありません。なぜwith基準でそれが起こるのですか?

Controller.php

public function actionIndex()
{
    $dayofweek = date('w');
    $criteria = new CDbCriteria;
    $criteria->select=array("
        CASE 
            WHEN weekday >= $dayofweek
            THEN CONCAT( DATE_ADD(CURDATE(), INTERVAL weekday - $dayofweek DAY), ' ', event_time )
            ELSE CONCAT( DATE_ADD(CURDATE(), INTERVAL 7 - $dayofweek + weekday DAY), ' ', event_time )
        END as revent_datetime,

        CASE 
            WHEN weekday >= $dayofweek AND list_time IS NOT NULL
            THEN CONCAT( DATE_ADD(CURDATE(), INTERVAL weekday - $dayofweek DAY), ' ', list_time )
            ELSE CONCAT( DATE_ADD(CURDATE(), INTERVAL 7 - $dayofweek + weekday DAY), ' ', list_time )
        END as rlist_datetime
    ");

    $criteria->with=array('profile'); // Thats the line w/ problem.

    $dataProvider=new CActiveDataProvider('Eventsreminder', array(
            'criteria' => $criteria
    ));

    $this->render('index',array(
        'dataProvider'=>$dataProvider,
    ));
}

出力:

$dataProvider->profile->name = Profile Test
$dataProvider->revent_datetime = NULL // here is the problem
$dataProvider->rlist_datetime = 2013-01-11 20:00:00
4

1 に答える 1

3

ええと、select で関数を使用している場合は、CDbExpression を作成する必要があります。

$criteria->select=array(
    new CDbExpression("CASE 
        WHEN weekday >= $dayofweek
        THEN CONCAT( DATE_ADD(CURDATE(), INTERVAL weekday - $dayofweek DAY), ' ', event_time )
        ELSE CONCAT( DATE_ADD(CURDATE(), INTERVAL 7 - $dayofweek + weekday DAY), ' ', event_time )
    END as revent_datetime"),
    new CDbExpression("CASE 
        WHEN weekday >= $dayofweek AND list_time IS NOT NULL
        THEN CONCAT( DATE_ADD(CURDATE(), INTERVAL weekday - $dayofweek DAY), ' ', list_time )
        ELSE CONCAT( DATE_ADD(CURDATE(), INTERVAL 7 - $dayofweek + weekday DAY), ' ', list_time )
    END as rlist_datetime")
);
于 2013-01-11T05:26:07.007 に答える