ZendFramework 2 下安装和配置 Doctrine 2 的步骤

一、确保 composer 正常

要确保 composer 能够正常的使用,如果因为GFW原因,可以尝试修改composer.json ,使用国内的镜像:


"repositories": [
{"type": "composer", "url": "http://packagist.phpcomposer.com"},
{"packagist": false}

二、添加模块依赖
直接上 composer 代码,以下配置内容加上了 zend-developer-tools、zftool、bj-profiler的模块依赖,这些模块配置很简单,官网上面都有,照着做就可以了。如果不需要,可以删除。


{
    "name": "Your project name",
    "description": "Your project description",
    "license": "BSD-3-Clause",
    "keywords": [
        ""
    ],
    "homepage": "Your project homepage",
    "require": {
        "php": ">=5.5",
        "zendframework/zendframework": "~2.5",
        "zendframework/zend-developer-tools": "dev-master",
        "zendframework/zftool": "dev-master",
        "bjyoungblood/bjy-profiler": "dev-master",
        "doctrine/doctrine-orm-module": "^0.9.1"
    },
    "repositories": [
        {"type": "composer", "url": "http://packagist.phpcomposer.com"},
        {"packagist": false}
    ]
}

三、修改 local.php 配置文件
如果没有local.php,就创建一个


$dbParams = array(
    'dbname' => 'dbname',
    'dbuser' => 'dbuser',
    'dbpass' => 'dbpass',
    'dbhost' => 'dbhost',
    'dbport' => 'dbport',
    // buffer_results - only for mysqli buffered queries, skip for others
    'options' => array(
        'buffer_results' => true
    )
);

return array(
    'dbParams'=>$dbParams,
    'doctrine' => array(
        'connection' => array(
            'orm_default' => array(
                'driverClass' => 'DoctrineDBALDriverPDOMySqlDriver',
                'params' => array(
                    'host' => $dbParams['dbhost'],
                    'port' => $dbParams['dbport'],
                    'user' => $dbParams['dbuser'],
                    'password' => $dbParams['dbpass'],
                    'dbname' => $dbParams['dbname'],
                    'charset' => 'UTF8'
                )
            )
        )
    )
);

四、修改模块配置文件
修改需要使用 Doctrine 的模块目录下的 config 子目录的配置文件 module.config.php,添加配置内容如下:

return array(
    /** 其他配置内容 **/
    /**
        * 部署 Doctrine
    */
    'doctrine' => array(
		'driver' => array(
		  __NAMESPACE__ . '_driver' => array(
			'class' => 'DoctrineORMMappingDriverAnnotationDriver',
			'cache' => 'array',
			'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity',  // Define path of entities
			)
		  ),
		  'orm_default' => array(
			'drivers' => array(
			  __NAMESPACE__ . 'Entity' => __NAMESPACE__ . '_driver'  // Define namespace of entities
			)
		  )
		)
	)
);

上述配置指定了该模块的 雷竞技苹果下载地址 Entty 目录在模块目录下的 src/模块名称/Entity 目录下

发表评论

电子邮件地址不会被公开。 必填项已用*标注