活到老学到老  

记录遇到问题的点点滴滴。

CI 视图兼容Smarty

8年前发布  · 995 次阅读
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Class MY_Loader
 */
class MY_Loader extends CI_Loader
{
    public function view($view, $vars = array(), $return = FALSE)
    {
        $ci = get_instance();
        /** @var CI_Config $config */
        $config = $ci->config;

        if ('smarty' == $config->item('view_template')) {
            /** @var CI_Smarty $smarty */
            $smarty = $ci->smarty;

            foreach ($vars as $name => $value) {
                $smarty->assign($name, $value);
            }
            return $smarty->display($view);
        } else {
            return parent::view($view, $vars, $return);
        }
    }
}