/** * 载入类或文件 */ public static function import($alias, $forceInclude = false) { if (isset(self::$_imports[$alias])) { // previously imported return self::$_imports[$alias]; } if (class_exists($alias, false) || interface_exists($alias, false)) { return self::$_imports[$alias] = $alias; } if (($pos = strrpos($alias, '\\')) !== false) { $namespace = str_replace('\\', '.', ltrim(substr($alias, 0, $pos), '\\')); if (($path = self::getPathOfAlias($namespace)) !== false) { $classFile = $path . DIRECTORY_SEPARATOR . substr($alias, $pos + 1) . '.php'; if ($forceInclude) { if (is_file($classFile)) { require $classFile; } else { throw new CException(Vii::t('vii', 'Alias "{alias}" is invalid. Make sure it points to an existing PHP file.', array('{alias}' => $alias))); } self::$_imports[$alias] = $alias; } else { self::$classMap[$alias] = $classFile; } return $alias; } else { throw new CException(Vii::t('vii', 'Alias "{alias}" is invalid. Make sure it points to an existing directory.', array('{alias}' => $namespace))); } } if (($pos = strrpos($alias, '.')) === false) { if ($forceInclude && self::autoload($alias)) { self::$_imports[$alias] = $alias; } return $alias; } $className = (string) substr($alias, $pos + 1); $isClass = $className !== '*'; if ($isClass && (class_exists($className, false) || interface_exists($className, false))) { return self::$_imports[$alias] = $className; } if (($path = self::getPathOfAlias($alias)) !== false) { if ($isClass) { if ($forceInclude) { if (is_file($path . '.php')) { require $path . '.php'; } else { throw new CException(Vii::t('vii', 'Alias "{alias}" is invalid. Make sure it points to an existing PHP file.', array('{alias}' => $alias))); } self::$_imports[$alias] = $className; } else { self::$classMap[$className] = $path . '.php'; } return $className; } else { if (self::$_includePaths === null) { self::$_includePaths = array_unique(explode(PATH_SEPARATOR, get_include_path())); if (($pos = array_search('.', self::$_includePaths, true)) !== false) { unset(self::$_includePaths[$pos]); } } array_unshift(self::$_includePaths, $path); if (self::$enableIncludePath && set_include_path('.' . PATH_SEPARATOR . implode(PATH_SEPARATOR, self::$_includePaths)) === false) { self::$enableIncludePath = false; } return self::$_imports[$alias] = $path; } } else { throw new CException(Vii::t('vii', 'Alias "{alias}" is invalid. Make sure it points to an existing directory or file.', array('{alias}' => $alias))); } }
<?php /** * 继承控制器类 * @author haibin <*****@*****.**> * @version $Id: Controller.php 1 2014-01-05 17:21:49Z haibin $ */ Vii::import('app.includes.Smarty'); class Controller extends CController { public $smarty; public $assets; public $skin; public $tpl; public $js; public function init() { $smarty = new Smarty(); $smarty->template_dir = 'templates/'; $smarty->compile_dir = 'data/templates_c/'; $smarty->config_dir = '/data/configs/'; $smarty->cache_dir = '/data/cache/'; //注册标签方法 $smarty->registerPlugin('function', 'label', array('Label', 'show')); $this->smarty = $smarty; $this->assign('smarty', $this->smarty); $this->initTheme(); $this->initStatics(); } /** *初始化风格