如何使用CodeIgniter中的Output类发送输出

时间:2014-04-09 22:34:42

标签: php codeigniter output

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Css extends CI_Controller {

/**
 * Css Page
 *
 * Maps to the following URL
 *      http://example.com/index.php/css
 *  - or -  
 *      http://example.com/index.php/css/index
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/base/<method_name>
 * @see http://codeigniter.com/user_guide/general/urls.html
 */

public function __construct() {
    parent::__construct();
    $this->load->helper('directory');
    $this->load->helper('file');
    $this->load->helper('url');
    //$this->output->cache(1440);
}

public function retrieve($module) {
    $template = $this->config->item('template');
    $dir = '/home/examples/public_html/application/views/resources/' . $template . '/modules/' . $module . '/';

    if(is_dir($dir)) {
        $map = directory_map($dir, 10);
    }
    else {
        show_404(site_url('/css/' . $module));
    }

    $this->output->set_content_type('text/css');
    $this->_process($map);
    //$this->output->get_output();
    //$this->load->view('resources/'.$template.'/modules/'.$module.'/'.$file);
}

public function _process($arr) {
    foreach($arr as $key => $val) {
        if(is_array($val)) {
            $this->_process($val);
        }
        else {
            $data = read_file($val);
            $this->output->append_output($data);
        }
    }
}
}

/* End of file css.php */
/* Location: ./application/controllers/css.php */

在我的检索方法中..我调用_process方法并将$ data附加到Output类变量,但是我不确定在递归_process函数完成后如何将输出发送到浏览器。任何人对过程功能完成后如何将输出发送到浏览器有任何想法?

1 个答案:

答案 0 :(得分:0)

您需要调用这些函数:

$this->output->set_content_type('text/css');
    $this->_process($map);

$this->load->view();

即。在控制器方法(函数)的末尾