Is there any way to the get the string representation of the query from CDbCriteria? For testing and debugging purposes.
相关问题
- Yii - Eliminate default controller ID for a module
- how to change csrf field id from YII_CSRF_TOKEN to
- Load balancing with Yii sessions
- Yii uploading pictures
- How to Auto Login and Redirect After Registration
相关文章
- Can you run console jobs from yii2-basic?
- How to do a bulk database insert in Yii2?
- Yii2 - check if the user is logged in view
- Call static method from a string name in PHP
- radioButtonList checked by default
- Postgres error: null value in column “id” - during
- Add column as link in CGridView
- yii : how to ajax update the cgridview
You can use logging and profiling configuring your main.php like this:
I spend a lot amount of time for finding the answer to this question, so thought of sharing it with you guys. Hope this saves your precious time.
As mentioned by Jon above:
CDbCriteria
does not aggregate enough information to construct the full query, you have to use the model class information also on which you will put the query constraints.As the example given in Yii docs for CDbCriteria; this is how basically you use it-
Here
Post
is the name of the model on which you execute the query condition.So if you want to get the text representation of the query written in CDbCriteria, you have to involve the model information also i.e. Post.
This is how you can do it -
When you print the value in
$query
variable it prints the raw query.Hope this helps.