我從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,管理面板,網站中使用它們。感謝您的指導。