Yii Framework Forum: How To Print Value On Search() To Check Them - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Print Value On Search() To Check Them How to print value on search() to check them Rate Topic: -----

#1 User is offline   ferminako 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 27-February 13

Posted 16 May 2013 - 04:10 AM

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!
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,041
  • Joined: 16-February 11
  • Location:Japan

Posted 16 May 2013 - 06:36 AM

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.yiiframew.../topics.logging
0

#3 User is offline   ferminako 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 27-February 13

Posted 16 May 2013 - 09:45 AM

View Postsoftark, on 16 May 2013 - 06:36 AM, said:

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.yiiframew.../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?
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,041
  • Joined: 16-February 11
  • Location:Japan

Posted 16 May 2013 - 06:13 PM

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".
0

#5 User is offline   sefburhan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 136
  • Joined: 08-February 12
  • Location:islamabad

Posted 17 May 2013 - 12:20 AM

View Postferminako, on 16 May 2013 - 04:10 AM, said:

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!


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']);
0

#6 User is offline   ferminako 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 27-February 13

Posted 17 May 2013 - 02:07 AM

View Postfburhan89, on 17 May 2013 - 12:20 AM, said:

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...
0

#7 User is offline   ferminako 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 64
  • Joined: 27-February 13

Posted 17 May 2013 - 02:07 AM

View Postsoftark, on 16 May 2013 - 06:13 PM, said:

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".

thx you too!
0

#8 User is offline   le_top 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 281
  • Joined: 08-June 10
  • Location:France

Posted 17 May 2013 - 05:23 PM

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.
0

#9 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,041
  • Joined: 16-February 11
  • Location:Japan

Posted 17 May 2013 - 09:15 PM

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.
0

#10 User is offline   le_top 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 281
  • Joined: 08-June 10
  • Location:France

Posted 19 May 2013 - 01:57 PM

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.
1

#11 User is offline   sefburhan 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 136
  • Joined: 08-February 12
  • Location:islamabad

Posted 20 May 2013 - 02:58 AM

View Postferminako, on 17 May 2013 - 02:07 AM, said:

Thx for your trick, I hadn't realized it...


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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users