我从Zend框架1.4至2.4迁移的项目,我有一类“供应商/自定义/班/ user.php的”Zend框架2 Access数据库从定制库
<?php
namespace Classes;
use Zend\Db\TableGateway\TableGateway;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Db\Adapter\Adapter;
class User
{
public function getItemById($id)
{
//$config = $this->getServiceLocator()->get('config');
//This only work in controller
$configs = array();
$adapter = new Adapter($configs);
$projectTable = new TableGateway('project', $adapter);
$rowset = $projectTable->select(array('type' => 'PHP'));
echo 'Projects of type PHP: ';
foreach ($rowset as $projectRow) {
echo $projectRow['name'] . PHP_EOL;
}
}
}
?>
我需要加载在我的文件“config/autoload”,global.php和local.php中合并配置。 $config = $this->getServiceLocator()->get('config');
有人可以指导我如何从自定义类中获取这些配置。基本上我试图做的是编写一组类,如用户,项目,模型以外的客户,并通常在所有模块,如CMS,管理面板,网站中使用它们。感谢您的指导。