[ERLEDIGT] - SQL-Ausgabe

Hi, ich habe eine MANY-MANY-MANY - Beziehung um diese zu kontrollieren, würde ich mir gerne via print_r() oder ähnlich das SQL-STATEMENT ausgeben lassen.

Kennt jemand eine Methode?

Aktivier doch einfach CWebLogroute, dann siehst du deine ganzen Queries am Ende der Seite.

http://blog.mbischof.de/dbprofiling-mit-yii

passieren tut leider nichts.


	'components'=> array(

		'log' => array(

			'class' => 'CLogRouter',

			'routes' => array(

				array(

					'class'	=> 'CFileLogRoute',

					'levels'=> 'error, warning',

				),

				array(

					'class' => 'CWebLogRoute'

				),

			),

		),

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

		),

		'db' => array(

			'connectionString'	=> 'xxx',

			'charset'			=> 'utf8',

			'username'			=> 'xxx',

			'password'			=> 'xxx',

			'enableProfiling'	=> true,

		),

		'urlManager'=> array(

		),

	),

@mbi:

Eigentlich gehts noch einfacher. enableProfiling brauchst du nur,wenn du die verbratene Zeit für die Statements mit messen willst. Damit die Ergebnisse angezeigt werden, braucht man dann aber auch eine CProfileLogroute.

@yii:

Hast du log in der Konfiguration unter preload mit aufgeführt?

Die Minimalkonfiguration sieht so aus:


    'preload'               => array('log'),


    'components'=>array(


        'db'=>array(

            'connectionString' => '*****',

            'username' => '*****',

            'password' => '*****',

            //'enableParamLogging' => true,  // Logt die verwendeten Parameter

        ),


        'log' => array(

            'class' => 'CLogRouter',

            'routes' => array(

                array(

                    'class'=>'CWebLogRoute'

                ),

            ),

        ),

    ),



Will man die verwendeten Parameter mit loggen, kann man noch enableParamLogging aktivieren.

Meine Konfiguration. Muss im View irgendetwas aufgerufen? echo DEBUG-Meldung?


<?php


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

	'basePath'	=> dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'		=>'xxx |',


	// preloading 'log' component

	'preload'	=> array('log'),


	// autoloading model and component classes

	'import'	=> array(

		'application.models.*',

		'application.components.*',

	),


	// application components

	'components'=> array(

		'log' => array(

			'class' => 'CLogRouter',

			'routes' => array(

				array(

					'class'	=> 'CFileLogRoute',

					'levels'=> 'error, warning',

				),

				array(

					'class' => 'CWebLogRoute'

				),

			),

		),

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

		),

		'db' => array(

			'connectionString'	=> 'xxx',

			'charset'			=> 'utf8',

			'username'			=> 'xxx',

			'password'			=> 'xxx',

			'enableProfiling'	=> true,

		),

		'urlManager'=> array(

		),

	),


	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']

	'params'=>array(

		// this is used in contact page

		'adminEmail'=> 'xxx',

		'homepage'	=> 'xxx',

		'url'		=> 'xxx',

	),

);

Im View nicht, aber hast recht: Das Log erscheint nur im DEBUG-Mode. Also schreib sowas in deine index.php:


defined('YII_DEBUG') or define('YII_DEBUG',true);


defined('YII_DEBUG') or define('YII_DEBUG',true);

Diese Zeile habe ich jeweils in folgenden Dateien getestet

  • layouts/main.php

  • site/index.php

  • config/main.php

  • yiic.php




Application Log

Timestamp 	Level 	Category 	Message

16:43:08.865984 	trace 	system.web.CModule 	


Loading "log" application component


16:43:08.870970 	trace 	system.web.CModule 	


Loading "request" application component


16:43:08.875394 	trace 	system.web.CModule 	


Loading "urlManager" application component


16:43:08.910824 	trace 	system.web.CModule 	


Loading "clientScript" application component



Die Ausgabe erfolgt jedoch nur auf der Startseite, mmh?

Probiers mal in der index.php. In den Viewfiles ist es zu spät, weil die erst beim Rendern eingebunden werden.

meine index.php


<?php


// change the following paths if necessary

$yii=dirname(__FILE__).'/../yii/framework/yii.php';

$config=dirname(__FILE__).'/protected/config/main.php';


// remove the following line when in production mode

defined('YII_DEBUG') or define('YII_DEBUG',true);


require_once($yii);

Yii::createWebApplication($config)->run();



Dennoch erscheint das "Anwendungsprotokoll" nur bei


http://localhost/blog2/index.php?r=site/index

Du hast immernoch keine CProfileLogRoute angegeben…


<?php


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

        'basePath'      => dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

        'name'          =>'xxx |',


        // preloading 'log' component

        'preload'       => array('log'),


        // autoloading model and component classes

        'import'        => array(

                'application.models.*',

                'application.components.*',

        ),


        // application components

        'components'=> array(

                'log' => array(

                        'class' => 'CLogRouter',

                        'routes' => array(

                                array(

                                        'class' => 'CProfileLogRoute',

                                        'levels'=> 'error, warning',

                                ),

                                array(

                                        'class' => 'CWebLogRoute'

                                ),

                        ),

                ),

                'user'=>array(

                        // enable cookie-based authentication

                        'allowAutoLogin'=>true,

                ),

                'db' => array(

                        'connectionString'      => 'xxx',

                        'charset'                       => 'utf8',

                        'username'                      => 'xxx',

                        'password'                      => 'xxx',

                        'enableProfiling'       => true,

                ),

                'urlManager'=> array(

                ),

        ),


        // application-level parameters that can be accessed

        // using Yii::app()->params['paramName']

        'params'=>array(

                // this is used in contact page

                'adminEmail'=> 'xxx',

                'homepage'      => 'xxx',

                'url'           => 'xxx',

        ),

);

kein Unterschied

Das Anwendungsprotokoll erscheint nur bei (site - Controller)


http://localhost/blog2/index.php?r=site/index


http://localhost/blog2/index.php?r=site/login


http://localhost/blog2/index.php?r=site/contact

Wenn ich zum Beispiel einen anderen Controller ausführe dann erscheint das Anwendungsprotokoll nicht mehr.


http://localhost/blog2/index.php?r=search/car

mach mal die levels weg bei der profile log route.

nothing… :(

Dann liegt das Problem aber woanders. Die Konfiguration ist richtig und es funktioniert beim Site-Controller ja auch.

Du beendest nicht zufällig jede action mit die() oder irgendwie sowas, oder?!

Fehler gefunden, in meinen anderen Controllern funktioniert alles wunderbar.

Nur in diesem nicht, weil ich ein exit() ausführe.

Habe ich kein Ergebnis gefunden rufe ich einen anderen view auf. Führe ich kein exit() aus, so führt yii beide render() aus!




	if ( $results === null )

	{

		$this->setPageTitle("xxxx");

		$this->render('notFound',

			array(

			)

		);

		exit();

	}


	$this->setPageTitle("yyy");

	$this->render('search', 

		array(

			'aSimilar'		=> $aSimilar,

		) 

	);



Anstatt ein exit() kannst du auch einfach ein "return" benutzten, wenn du die action verlassen willst.

Nur nochmal der Korrektheit halber: CProfileLogroute brauchst du nicht, um SQL-Statements auszugeben. Die ist nur für Zeitmessungen nötig…

Danke, hat wunderbar funktioniert!!!!

danke für die Info!