Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 2.0.2:Processing Output
#1

[eluser]Abdullah M.[/eluser]
I use this Processing Output function _output(), it work very good with me, but in my controller some output like json, image, i wonn't proccessed by this function!!

so,How _output() function works only in specific type of header?
#2

[eluser]TWP Marketing[/eluser]
Did you set the mime type? The user manual lists the available functions to enable usage with various mime types: file:///home/twp/Dev/drcliche/user_guide/libraries/output.html

Read about this function in particular: $this->output->set_content_type();
#3

[eluser]Abdullah M.[/eluser]
first, thank you.
I use _output() function to add header in footer to my output..
the problem is in my controler some function return json type , so I need _output() ignore this functions and don't add header and footer to it>>
#4

[eluser]TWP Marketing[/eluser]
Where is the function _output() located? I'm not familiar with it. Is it a php standard function or part of the CI libraries?
#5

[eluser]Abdullah M.[/eluser]
in core function
http://ellislab.com/codeigniter/user-gui...tml#output
#6

[eluser]TWP Marketing[/eluser]
Ok, You are overriding the standard CI output class. That means you must handle all java (json) and other output processing yourself, in your _output() function. That may not be what you want.

Is there some reason you don't use the usual loader class ($this->load->view() )? It would seem to be much easier to implement.

I have NOT used the overide function _output() in any of my code, so I cannot advise on how it "should" be written.

Is there anyone in the community that can offer more detailed advice in this case?
#7

[eluser]osci[/eluser]
for javascript i.e.
Code:
header('Content-Type: text/javascript; charset=UTF-8'); // Make output a real JavaScript file!
echo $output; // Now we can send data to the browser because all headers have been set!
and don't echo anything before.
#8

[eluser]Abdullah M.[/eluser]
I make this soulution:
Replacing Core Class CI_Output and add this function _set_stop_output to function where i wonn't _output() work...

It solved my problem

thank you all...

Code:
<?php
class MY_Output extends CI_Output {
    
    var $stop_output;
    function __construct(){
        parent::__construct();
        $this->stop_output = false;
    }
    
    function _set_stop_output($status=true){
        $this->stop_output = $status;
        return $this;
    }

    // --------------------------------------------------------------------

    /**
     * Display Output
     *
     * All "view" data is automatically put into this variable by the controller class:
     *
     * $this->final_output
     *
     * This function sends the finalized output data to the browser along
     * with any server headers and profile data.  It also stops the
     * benchmark timer so the page rendering speed and memory usage can be shown.
     *
     * @access    public
     * @return    mixed
     */
    function _display($output = '')
    {
        // Note:  We use globals because we can't use $CI =& get_instance()
        // since this function is sometimes called by the caching mechanism,
        // which happens before the CI super object is available.
        global $BM, $CFG;

        // Grab the super object if we can.
        if (class_exists('CI_Controller'))
        {
            $CI =& get_instance();
        }

        // --------------------------------------------------------------------

        // Set the output data
        if ($output == '')
        {
            $output =& $this->final_output;
        }

        // --------------------------------------------------------------------

        // Do we need to write a cache file?  Only if the controller does not have its
        // own _output() method and we are not dealing with a cache file, which we
        // can determine by the existence of the $CI object above
        if ($this->cache_expiration > 0 && isset($CI) && ! method_exists($CI, '_output'))
        {
            $this->_write_cache($output);
        }

        // --------------------------------------------------------------------

        // Parse out the elapsed time and memory usage,
        // then swap the pseudo-variables with the data

        $elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end');

        if ($this->parse_exec_vars === TRUE)
        {
            $memory     = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB';

            $output = str_replace('{elapsed_time}', $elapsed, $output);
            $output = str_replace('{memory_usage}', $memory, $output);
        }

        // --------------------------------------------------------------------

        // Is compression requested?
        if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE)
        {
            if (extension_loaded('zlib'))
            {
                if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
                {
                    ob_start('ob_gzhandler');
                }
            }
        }

        // --------------------------------------------------------------------

        // Are there any server headers to send?
        if (count($this->headers) > 0)
        {
            foreach ($this->headers as $header)
            {
                @header($header[0], $header[1]);
            }
        }

        // --------------------------------------------------------------------

        // Does the $CI object exist?
        // If not we know we are dealing with a cache file so we'll
        // simply echo out the data and exit.
        if ( ! isset($CI))
        {
            echo $output;
            log_message('debug', "Final output sent to browser");
            log_message('debug', "Total execution time: ".$elapsed);
            return TRUE;
        }

        // --------------------------------------------------------------------

        // Do we need to generate profile data?
        // If so, load the Profile class and run it.
        if ($this->enable_profiler == TRUE)
        {
            $CI->load->library('profiler');

            if ( ! empty($this->_profiler_sections))
            {
                $CI->profiler->set_sections($this->_profiler_sections);
            }

            // If the output data contains closing </body> and </html> tags
            // we will remove them and add them back after we insert the profile data
            if (preg_match("|</body>.*?</html>|is", $output))
            {
                $output  = preg_replace("|</body>.*?</html>|is", '', $output);
                $output .= $CI->profiler->run();
                $output .= '</body></html>';
            }
            else
            {
                $output .= $CI->profiler->run();
            }
        }

        // --------------------------------------------------------------------

        // Does the controller contain a function named _output()?
        // If so send the output there.  Otherwise, echo it.
        if (method_exists($CI, '_output') and !$this->stop_output)
        {
            $CI->_output($output);
        }
        else
        {
            echo $output;  // Send it to the browser!
        }

        log_message('debug', "Final output sent to browser");
        log_message('debug', "Total execution time: ".$elapsed);
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB