2009-08-12 1 views
0

, 즉 첨부 :

<?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; 
?> 

어떻게 로그 배열을 양식으로 표시 할 수 있습니까 ....?

어떻게 "응용 프로그램/조회/스크립트/기타/index.phtml"나는 http://framework.zend.com/manual/en/zend.registry.html 방문

+0

당신이 설명 할 수 아름다운 사용자 인터페이스를 생성하는 사용자 정의 도우미와 print_r을 대체하는 것을 잊지 말아? – UpTheCreek

답변

-1

및 유일한에 "응용 프로그램/logmessage/log.phtml"에서 $에게 logArray()를 호출 수있는 I

<?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); 

?> 

에 약간의 코드 : 추가 된입니다.

+0

Zend_Registery는 자동 완성 기능을 끌 것이므로 사용하지 않는 것이 좋습니다. D –

0

로거에이 코드를 추가

public $logArray; 

도 이제 view에서 $ logArray에 액세스 할 수 있습니다

$this->logArray = array("Message" => $messageText, "Priority" => $priority, 
       "Line" => $backTraceLine, "File" => $backTraceFile); 

} 

으로 마지막 줄을 변경 controller, form을, 등 우리가 전화를 예를 들어 로거를 controller에 입력하고 view

,

는 acheive 무엇을하려고하는

echo $this->myCustomHelper($this->logArray);