yaf
yaf copied to clipboard
如果使自己的文件也使用namespace
yaf自己的类可以开启namespace调用,请问我自己的程序文件也希望使用namespace来规划,如:
getAppDirectory(); echo $this->_request->getActionName(); $this->_view->assign('word', 'Hello World'); } } 现在是运行不了的,请问怎么做比较好呢
1、修改yaf的配置项
yaf.use_namespace = 1
yaf.use_spl_autoload = 1
2、在你的Bootstrap文件中引入composer的autoload.php就可以。
<?php
use \Yaf\Bootstrap_Abstract;
use \Yaf\Dispatcher;
use \Yaf\Loader;
/**
* Class Bootstrap
*/
class Bootstrap extends Bootstrap_Abstract
{
/**
* @param Dispatcher $dispatcher
*/
function _initComposerAutoload(Dispatcher $dispatcher)
{
$autoload = APPLICATION_PATH . '/vendor/autoload.php';
if (file_exists($autoload)) {
Loader::import($autoload);
}
}
}
开启了spl_autoload效率会受影响。希望Yaf本身能支持项目引入命名空间。
鸟哥好像对命名空间没什么感觉,还停留在pecl时代
@JianfuLi 感谢你提供的方法。
@JianfuLi 多谢你提供的方法。
已经解决 参考这里 https://github.com/letwang/HookPHP/blob/master/app/admin/models/Rbac/Role.php
1、修改yaf的配置项
yaf.use_namespace = 1 yaf.use_spl_autoload = 1
2、在你的Bootstrap文件中引入composer的autoload.php就可以。
<?php use \Yaf\Bootstrap_Abstract; use \Yaf\Dispatcher; use \Yaf\Loader; /** * Class Bootstrap */ class Bootstrap extends Bootstrap_Abstract { /** * @param Dispatcher $dispatcher */ function _initComposerAutoload(Dispatcher $dispatcher) { $autoload = APPLICATION_PATH . '/vendor/autoload.php'; if (file_exists($autoload)) { Loader::import($autoload); } } }
使用了这个方法后报错: [1] 86596 segmentation fault /usr/local/Cellar/[email protected]/7.3.24/bin/php cli.php