Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果使自己的文件也使用namespace #159

Open
9466 opened this issue Mar 25, 2015 · 7 comments
Open

如果使自己的文件也使用namespace #159

9466 opened this issue Mar 25, 2015 · 7 comments

Comments

@9466
Copy link

9466 commented Mar 25, 2015

yaf自己的类可以开启namespace调用,请问我自己的程序文件也希望使用namespace来规划,如:

getAppDirectory(); echo $this->_request->getActionName(); $this->_view->assign('word', 'Hello World'); } } 现在是运行不了的,请问怎么做比较好呢
@JianfuLi
Copy link

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);
        }
    }
}

@yqt
Copy link

yqt commented Jul 28, 2015

开启了spl_autoload效率会受影响。希望Yaf本身能支持项目引入命名空间。

@lovelock
Copy link

鸟哥好像对命名空间没什么感觉,还停留在pecl时代

@shyandsy
Copy link
Contributor

shyandsy commented Jan 4, 2016

@JianfuLi 感谢你提供的方法。

@creazy412
Copy link

@JianfuLi 多谢你提供的方法。

@letwang
Copy link

letwang commented Dec 6, 2018

已经解决 参考这里
https://github.com/letwang/HookPHP/blob/master/app/admin/models/Rbac/Role.php

@ghxter
Copy link

ghxter commented Feb 24, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants