How To Print Value On Search() To Check Them

How can I print the values that search() recieve?

Because I need to check something… I’ve tried with echo and other like using js alerts but I cant get the values…




$criteria->compare('t.email',$this->email,true);

                $criteria->compare('t.telefono',$this->telefono,true);

....




echo "<script type='text/javascript'>

alert('".$f1."');

console.log('".$f1."');

</script>";

echo $f1;


$criteria->addBetweenCondition('t.field',$f1,$f2,'AND');



How can I print these to check them?

Thx!

Hi ferminako,

You can use CWebLogRoute to print the values of a variable.

First you have to enable the CWebLogRoute in your ‘config/main.php’.




	'log'=>array(

		'class'=>'CLogRouter',

		'routes'=>array(

			array(

				'class'=>'CFileLogRoute',

				'levels'=>'error, warning',

			),

			/* here we enable CWebLogRoute for tracing */

			array(

				'class'=>'CWebLogRoute',

				'levels' => 'trace',

				'categories' => 'application.*',

			),

		),

	),



And then you can insert Yii::trace() in your code to trace the values of a variable.




$criteria->compare('t.email',$this->email,true);

...

Yii::trace('$f1 = '. $f1);

Yii::trace('$f2 = '. $f2);

...

$criteria->addBetweenCondition('t.field',$f1,$f2,'AND');



Check the following section of the guide: http://www.yiiframework.com/doc/guide/1.1/en/topics.logging

Thx a lot, with that solution ,it works…but I have another problem because the advanced search uses ajax for submit so the page doesn’t refresh and the log neither do it…and I can’t check changes in the values of $f1 and $f2… What can I do?

You can use an ordinary file log.




               'routes'=>array(

                        array(

                                'class'=>'CFileLogRoute',

                                'levels'=>'error, warning',

                        ),

                        /* dedicated log file for tracing */

                        array(

                                'class'=>'CFileLogRoute',

				'logFile' => 'trace.log',

                                'levels'=>'trace',

                                'categories' => 'application.*',

                        ),

                        ...



You can not check the values on the fly, but can see them in the log file that is "application/runtime/trace.log".

User Session : assign values during searching and get it where you want to show, if using ajax : then create a function in controller in print its result…IT has the advantages to take less time during development+ your are using for testing!

Yii::app()->session[‘var’] = ‘value’;

echo Yii::app()->session[‘var’]; // Prints “value”

unset(Yii::app()->session[‘var’]);

Thx for your trick, I hadn’t realized it…

thx you too!

Most of the time, looking at the GET request made by the browser is sufficient to get an idea of what has been sent, and hence very probably received.

So everyone has his/her own favorite style of debugging, but I think the logging to the file is the most basic and reliable measure to trace the program. You can count on it in almost all the situations.

However, what I usually do is the step tracing of the code in IDE or the browser’s developer’s tool. :)

And for CGridView, you may note that turning off ajax updating will make debugging far easier, just as le_top has implicitly suggested.

Acutally, the GET request is an ajx request, but I use the browser’s developer debugging tool to get the request.

When I want to examine a particular case, I even open that link in a new tab. That way all the search parameters are in the GET request and the page can be reloaded (F5) using the same parameters which can be handy during debug.

Welcome: if having more problems in it, let me know , worked on it alot!!!