2

This is my code:

$ptoRequests = CalendarRequest::model()
                    ->with(array('intervals'))
                    ->findAll(array('order' => 't.time, t.id desc',
                'condition' => 'eventId in (5, 7, 8, 9, 10, 11) and statusId in (1,2) and userId = "' . $user->userId . '" and (intervals.enddate >= :from)',
                'params' => array('from' => date("Y-m-d"))));
                echo "<pre>"; var_dump($ptoRequests->getQuery()); echo "</pre>"; exit();

What I want to achieve is to print the last query executed. The getQuery() function returns me a fatal error. What should I do ? Thx

3
  • 2
    stackoverflow.com/questions/21231729/yii-echo-the-last-query On this github page: github.com/yiisoft/yii2/issues/1173, you can see developers bounced your specific functionality at the moment is was requested Commented Mar 16, 2015 at 13:38
  • I tried with logs but the application.log file is empy Commented Mar 16, 2015 at 13:43
  • I am no YII pro.. But could it be the with() function is not satified in the model and therefor no query has been made? Commented Mar 16, 2015 at 13:47

1 Answer 1

1

Try this

echo ModelClassName::model()->
getCommandBuilder()->
createFindCommand('table_name', $criteria)->text;

where $criteria is

$criteria= new CDbCriteria();
$criteria->condition="your query condition";
$criteria->order="t.time desc"

check CDbCriteria here for reference

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.