Welcome Guest, Not a member yet? Register   Sign In
Profiler: What Views loaded
#1

[eluser]dmayo2[/eluser]
When you enable and output the Profiler info, it can be quite informative. However, for the life of me I can't seem to find any way to get what View(s) have been loaded.

Any ideas?
Thanks.
#2

[eluser]Harold Villacorte[/eluser]
The Loader.php class line #836 puts out a debug log message for each file that is loaded.
#3

[eluser]dmayo2[/eluser]
Thanks for that tip.

I'm able to output the log, but I'm having a tough time getting to the view that's loaded.

I put the log output class call in the controller, but my output stops when the controller class has been initialized, and the loading of the view comes after that.

So, I tried to move the call to the view itself to no avail.

Any additional thoughts?

Here's a complete output of the log when viewed after the entire page renders in browser. By putting my call in the controller, I don't get the last (top 5 as the array has been krsort-ed)
[20] => DEBUG - 2013-04-16 12:29:50 --> Total execution time: 0.0544
[21] => DEBUG - 2013-04-16 12:29:50 --> Final output sent to browser
[22] => DEBUG - 2013-04-16 12:29:50 --> Helper loaded: text_helper
[23] => DEBUG - 2013-04-16 12:29:50 --> Language file loaded: language/english/profiler_lang.php
[24] => DEBUG - 2013-04-16 12:29:50 --> File loaded: /.../application/views/welcome_message.php

[25] => DEBUG - 2013-04-16 12:29:50 --> Controller Class Initialized
[26] => DEBUG - 2013-04-16 12:29:50 --> Database Driver Class Initialized
[27] => DEBUG - 2013-04-16 12:29:50 --> Helper loaded: form_helper
[28] => DEBUG - 2013-04-16 12:29:50 --> Helper loaded: url_helper
[29] => DEBUG - 2013-04-16 12:29:50 --> Loader Class Initialized
[30] => DEBUG - 2013-04-16 12:29:50 --> Language Class Initialized
[31] => DEBUG - 2013-04-16 12:29:50 --> Global POST and COOKIE data sanitized
[32] => DEBUG - 2013-04-16 12:29:50 --> CRSF cookie Set
[33] => DEBUG - 2013-04-16 12:29:50 --> XSS Filtering completed
[34] => DEBUG - 2013-04-16 12:29:50 --> XSS Filtering completed
[35] => DEBUG - 2013-04-16 12:29:50 --> XSS Filtering completed
[36] => DEBUG - 2013-04-16 12:29:50 --> Input Class Initialized
[37] => DEBUG - 2013-04-16 12:29:50 --> Security Class Initialized
[38] => DEBUG - 2013-04-16 12:29:50 --> Output Class Initialized
[39] => DEBUG - 2013-04-16 12:29:50 --> Router Class Initialized
[40] => DEBUG - 2013-04-16 12:29:50 --> URI Class Initialized
[41] => DEBUG - 2013-04-16 12:29:50 --> UTF-8 Support Enabled
[42] => DEBUG - 2013-04-16 12:29:50 --> Utf8 Class Initialized
[43] => DEBUG - 2013-04-16 12:29:50 --> Hooks Class Initialized
[44] => DEBUG - 2013-04-16 12:29:50 --> Config Class Initialized
#4

[eluser]Harold Villacorte[/eluser]
You can just extend the Log class. Here is a quick and dirty:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* Extends the CodeIgniter Log class.
*/
class MY_Log extends CI_Log {

    /**
     * Array of view files that have been loaded.
     *
     * @var type
     */
    public $view_files_loaded = array();

/**
  * Write Log File
  *
  * Generally this function will be called using the global log_message() function
  *
  * @param string the error level
  * @param string the error message
  * @param bool whether the error is a native PHP error
  * @return bool
  */
public function write_log($level = 'error', $msg, $php_error = FALSE)
{
  //------ The extension.  Adds view files to the public $view_files_loaded.-//
  if (strstr($msg, 'File loaded') && strstr($msg, 'views'))
  {
      $this->view_files_loaded[] = $msg;
  }
  //------End extension------------------------------------------------------//

  if ($this->_enabled === FALSE)
  {
   return FALSE;
  }

  $level = strtoupper($level);

  if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
  {
   return FALSE;
  }

  $filepath = $this->_log_path.'log-'.date('Y-m-d').'.php';
  $message  = '';

  if ( ! file_exists($filepath))
  {
   $message .= "<"."?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
  }

  if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
  {
   return FALSE;
  }

  $message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --&gt; '.$msg."\n";

  flock($fp, LOCK_EX);
  fwrite($fp, $message);
  flock($fp, LOCK_UN);
  fclose($fp);

  @chmod($filepath, FILE_WRITE_MODE);
  return TRUE;
}

}
// END MY_Log Class

/* End of file MY_Log.php */
/* Location: ./application/libraries/Log.php */
The $view_files_loaded array would be available anywhere.
Code:
var_dump($this->log->view_files_loaded);
It should be available to the Profiler class as well if you feel like extending that.
#5

[eluser]InsiteFX[/eluser]
Open up and view the .system/libaries/Profiler.php and you will see what is going on.

It does not output to a view, it just outputs html code.




Theme © iAndrew 2016 - Forum software by © MyBB