我在log.phtml中有一个数组,即:
<?php
//application/logmessage/log.phtml//
require_once 'Zend/Log.php';
require_once 'Zend/Log/Writer/Stream.php';
class Logger {
/**
* Array variable store full file back trace information.
*
* @access protected
*/
protected $backTrace = array();
/**
* Array variable store full message information.
*
* @access protected
*/
protected $messageInfo = array();
/**
* Constructor: loads the debug and error logs.
*
*/
public function __construct( $type, $msg ) {
$mock = new Zend_Log_Writer_Mock;
$logger = new Zend_Log( $mock );
$logger->$type( $msg );
// Get full message information.
array_push( $this->messageInfo, $mock->events[0] );
// Get full information of file, from where the message come.
array_push( $this->backTrace, debug_backtrace() );
// Set all required informationn in their respective variables.
$messageText = $this->messageInfo[0]["message"];
$priority = $this->messageInfo[0]["priorityName"];
$backTraceFile = $this->backTrace[0][0]["file"];
$backTraceLine = $this->backTrace[0][0]["line"];
$logArray = array( "Message" => $messageText, "Priority" => $priority,
"Line" => $backTraceLine, "File" => $backTraceFile );
}
}
?>
现在我想显示$ logArray数组和表单,我的表单文件如下:
<?php
//application/views/scripts/miscellaneous/index.phtml//
//require_once('../application/logmessage/log.phtml');
echo $this->form;
?>
如何显示带有表单的日志数组....?
我如何从“application / logmessage / log.phtml”返回$ logArray() “application / views / scripts / miscellaneous / index.phtml”
答案 0 :(得分:0)
在您的记录器中添加此代码:
public $logArray;
也用
更改最后一行$this->logArray = array( "Message" => $messageText, "Priority" => $priority,
"Line" => $backTraceLine, "File" => $backTraceFile );
}
现在您可以从view
,controller
,form
等访问$ logArray,例如我们在controller
中调用Logger并将其发送到view
}
/** Controller **/
$logger = new Logger($msg, $type);
$this->view->logArray = $loagger->logArray;
/** View **/
print_r($this->logArray);
不要忘记用自定义助手替换print_r
以创建漂亮的用户界面
echo $this->myCustomHelper($this->logArray);
答案 1 :(得分:-1)
我访问http://framework.zend.com/manual/en/zend.registry.html,我添加的唯一内容是:
<?php
//application/logmessage/log.phtml//
require_once 'Zend/Log.php';
require_once 'Zend/Log/Writer/Stream.php';
class Logger {
/**
* Array variable store full file back trace information.
*
* @access protected
*/
protected $backTrace = array();
/**
* Array variable store full message information.
*
* @access protected
*/
protected $messageInfo = array();
/**
* Constructor: loads the debug and error logs.
*
*/
public function __construct( $type, $msg ) {
$mock = new Zend_Log_Writer_Mock;
$logger = new Zend_Log( $mock );
$logger->$type( $msg );
//var_dump($mock->events[0]);
// Get full message information.
array_push( $this->messageInfo, $mock->events[0] );
// Get full information of file, from where the message come.
array_push( $this->backTrace, debug_backtrace() );
// Set all required informationn in their respective variables.
$messageText = $this->messageInfo[0]["message"];
$priority = $this->messageInfo[0]["priorityName"];
$backTracePath = $this->backTrace[0][0]["file"];
$backTraceLine = $this->backTrace[0][0]["line"];
$logArray = array( "Message" => $messageText, "Priority" => $priority,
"Line" => $backTraceLine, "Path" => $backTracePath );
// Pass the array for display.
Zend_Registry::set('logArray', $logArray);
}
}
?>
和
中的一些代码<?php
//application/views/scripts/miscellaneous/index.phtml//
echo $this->form;
$logArray = Zend_Registry::get('logArray');
print_r($logArray);
?>
效果很好。