Reputation: 2600
Using Yii Framework, how can I access Model Constant in Controller?
Model.php
...
const STATUS_ACTIVE=1;
...
Controller.php
...
$criteria->condition = 'status='.self::STATUS_ACTIVE;
...
Error:
Fatal error: Undefined class constant 'STATUS_ACTIVE' in ... on line X
Upvotes: 0
Views: 5249
Reputation: 634
Assuming you Model Class object is $model, it will be
$criteria->condition = 'status=' . $model::STATUS_ACTIVE;
Unsure how the chosen answer works - certainly did not work for me.
Upvotes: 0
Reputation: 12843
In your controller self is the controller's class who does not have this constant. I think you wanted:
Model::STATUS_ACTIVE
Where Model is the name of the model's class. ie:
$criteria->condition = 'status='.Model::STATUS_ACTIVE;
Upvotes: 8