views:

62

answers:

1

Hello, I have an array in a log.phtml, ie:

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

    }
}
?>

Now i want to display the $logArray array along with form, my form file is like:

<?php 
//application/views/scripts/miscellaneous/index.phtml//

//require_once('../application/logmessage/log.phtml');

    echo $this->form;
?>

How could i display Log array with form ....?

How could i return $logArray() from " application/logmessage/log.phtml " to " application/views/scripts/miscellaneous/index.phtml "

A: 

Hello. Thanks to All Mighty Allah, The Greatest one.. I visit http://framework.zend.com/manual/en/zend.registry.html and the only thing that i added is

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

and a little code in

<?php
//application/views/scripts/miscellaneous/index.phtml//


    echo $this->form;

    $logArray = Zend_Registry::get('logArray');
    print_r($logArray);

?>

It works Excellent..!