Ask a question:
Yaf. Use_namespace=1, how does the controller use namespace?
For example: content of index.php
use Yaf\Controller_Abstract;use Yaf\Dispatcher;class IndexController extends Controller_Abstract{ public function indexAction() { Dispatcher::getInstance()->disableView(0); echo 'Great,It Works!'; }}
Can't add namespace, the file name is index.php
How to deal with the passing, talk about
Reply content:
Ask a question:
Yaf. Use_namespace=1, how does the controller use namespace?
For example: content of index.php
use Yaf\Controller_Abstract;use Yaf\Dispatcher;class IndexController extends Controller_Abstract{ public function indexAction() { Dispatcher::getInstance()->disableView(0); echo 'Great,It Works!'; }}
Can't add namespace, the file name is index.php
How to deal with the passing, talk about
I also want to know the answer. Originally wanted to
一直报错。去掉namespace App\Controllers
就行。不知道怎么办了。
PHP.ini Open
yaf.use_namespace = 1yaf.use_spl_autoload = 1
The definition loader can be used in the public function
/** 自动加载器 modules */function autoload_modules($class){ $class = str_replace('\\', DIRECTORY_SEPARATOR, $class); ... $file = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'xxxx' . $class . '.php'; if( file_exists($file) ) Loader::import($file);}
Then use Spl_autoload_register to customize the loader in the Bootstrap file
不过开启 use_spl_autoload 会影响效率
开启的情况下, Yaf在加载不成功的情况下, 会继续让PHP的自动加载函数加载, 从性能考虑, 除非特殊情况, 否则保持这个选项关闭
use_spl_autoload
也是一直报错,原来是index里加了 namesapce App\Controllers