Yaf. Use_namespace=1, how does the controller use the namespace

Source: Internet
Author: User
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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.