如何在Yii 1中使用命名空间编程扩展

时间:2015-09-22 09:32:52

标签: php yii namespaces yii-extensions

我需要在Yii版本1项目中使用https://github.com/maxmind/GeoIP2-php扩展名(即没有名称空间概念项目)。

尝试:$reader = new \GeoIp2\Database\Reader('/path/to/GeoIP2-City.mmdb');

main.php有以下代码:

'import' => array(
    'common.extensions.*',
   )

此外,common / extensions文件夹在' GeoIP2'下具有上述扩展名。文件夹中。

但没有运气。错误是:

  

致命错误:Class' GeoIp2 \ Database \ Reader'找不到   ...... Controller.php上线..

任何想法。

1 个答案:

答案 0 :(得分:1)

通过执行以下操作来实现它:

main.php 中,我添加了以下几行:

Yii::setPathOfAlias('GeoIp2',Yii::getPathOfAlias('common.extensions.GeoIp2.src'));

controller-action 中,我修改了一行:

$reader = new GeoIp2\Database\Reader('/path/to/GeoIP2-City.mmdb');

如果有人知道其他任何方式,请告诉我们。

稍后可能会有所帮助。