Question

Trying to wade my way through Yii here, learning on the fly. We migrated a project off a unix server and on to a windows server and are experiencing some date/time difficulties.

I currently have a model "Activities" with a couple of properties happend_on, happend_at. What I would like to do is set these properties to UTC time dynamically on the fly. However I keep getting a Property Activity.happend_on, Activity.happend_on is not defined error from the CActiveRecord.php. I read a couple of places about overriding the set methods in the model (didnt work) and at your peril, overriding the magic _set method, also didn't work. I really want to set these properties on the fly.

    $activity = $this->loadModel ( $id );
    $time = $activity->happened_on . " " . $activity->happened_at;
    date_default_timezone_set ( "UTC" );
    $utc_date = DateTime::createFromFormat (
        'm/d/Y H:i:s', gmdate ( "m/d/Y H:i:s", strtotime ( $time ) ), new DateTimeZone ( 'UTC' ));

    $date = $utc_date;
    $date->setTimeZone ( new DateTimeZone ( $time_zone ) );
    // THESE ARE THE LINES THAT FAIL - NEED TO UPDATE THE PROPERTIES.
    $activity->happend_on = $date->format("m/d/Y");
    $activity->happend_at = $date->format("H:i:s");
Was it helpful?

Solution

You spelled happend_on and happend_at wrongly.

You meant to use happened_on and happened_at with an extra e.

This is very simple if you read the error message carefully, which is exactly what it says:
The attributes could not be found because you misspelled them!

Next time, if you get an is not defined error, check for the attributes mentioned in the error message.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top