Tracing Yii Execution: What Elements Make Up A Page?

As a newb to Yii who is working with a fairly large existing application, I am having trouble following the execution path, and determining which widgets and other Yii elements are being rendered to the page. Is there a good method for this? Perhaps a debug mode? Or if not, just a general algorithm for the steps I should take, starting with a url, to determine everything that is ultimately included on the page?

Thanks,

Jonah

First steps:

  1. Read the introduction to Yii execution flow here.

  2. You should enable web or file logging and study the logs.

/Tommy

Tommy, thank you for the links. Regarding Yii::trace(), I am a bit confused. How would I use it? Is there a place I can globally say "trace everything and display it"?

Jonah

  • "What makes up a page" is of course application dependent.

  • The section Fundamentals->View of the guide may be useful (reading all of the guide thoroughly is recommended)

  • You have to add trace() calls yourself.

  • Also intentionally add errors and study the stack trace.

  • Try increasing YII_TRACE_LEVEL in start script to include deeper stack trace in logs.

  • Add more levels to file logging (or just leave levels empty)




...

'log'=>array(

  'class'=>'CLogRouter',

    'routes'=>array(

      array(

        'class'=>'CFileLogRoute',

        'levels'=>'error, warning, trace, info',

      ),

    ),

),

...



/Tommy

Tommy,

Thanks again. I have read the logging section in the docs a couple times, and I still can’t figure out how I would actually use it in my code. I tried putting a call to Yii::trace(‘test’, ‘system.web.CController’) in one of my source files being executed but it didn’t seem to have any result. Can you give a quick code example? And afterwards, will I be looking for a log in the runtime folder, or is there some way to have the trace printed directly to the screen?

Thanks,

Jonah

Make sure the following line isn’t commented out in the startskript




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



You don’t need to specify the category parameter, it defaults to ‘application’ for your trace calls (contrary to ‘system’). I added an example below. It will log every level and category to both file and to the web page. As you already found out, the log file is written to protected/runtime/appplication.log.




array(

  ...

  ...

  // preloading 'log' component

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

  ...

  ...

  'components'=>array(

    'log'=>array(

    'class'=>'CLogRouter',

      'routes'=>array(

        array(

          'class'=>'CFileLogRoute',

          //'levels'=>'...',

          //'category'=>'...',

        ),

	array(

          'class'=>'CWebLogRoute',

          //'levels'=>'...',

          //'category'=>'...',

	),

      ),

    ),

    ...

    ...

  ),

  ...

  ...

);



/Tommy

Thank you very much! Working now… Don’t suppose you might be interested in:

http://www.yiiframework.com/forum/index.php?/topic/14929-seeking-yii-coaching-immediately/

One other question. The trace I see seems to be at a pretty high level of abstraction. I wanted to see how certain widgets and filters with those widgets, etc, were being called. Is there any way to do this?

You could hook your application up to a php debugger to see all of the inner workings step by step