2009-08-12 10 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; 
?> 

Log Arrayをフォームで表示するにはどうすればよいですか....?

私は http://framework.zend.com/manual/en/zend.registry.htmlを訪問

私は "アプリケーション/ LogMessageに/ log.phtml" から に)$ logArray(返すことができますどのように "アプリケーション/ビュー/スクリプト/その他の/ index.phtmlを"

+0

を作成するために、カスタムヘルパーとprint_rを置き換えることを忘れていけませんか? – UpTheCreek

答えて

-1

と私だけの事追加は、次のとおりです。

<?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の使用を避けることをお勧めします。なぜなら、Zend_Registeryは自動完了を無効にするからです。D –

0

あなたのロガーでこのコードを追加します。

public $logArray; 

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

} 

との最後の行を変更し、今あなたは私たちが呼ん例えばviewcontrollerformなどから$ logArrayにアクセスすることができますLogger in controllerを入力し、view

/** Controller **/ 
$logger = new Logger($msg, $type); 
$this->view->logArray = $loagger->logArray; 

/** View **/ 
print_r($this->logArray); 

はあなたがacheiveしようとしているかを説明することができ、美しいユーザーインターフェース

echo $this->myCustomHelper($this->logArray); 
関連する問題