zend framework 2.3 配置文件记录一下

分类:PHP | 作者:凹凸曼 | 发表于2014/08/05 zend framework 2.3 配置文件记录一下已关闭评论

最近一次在项目中使用zend framework 2.3 , 顺便记录一下它的配置文件
一、数据库适配器配置 global.php

return array(
		'db'=>array(

				'driver'=>'Pdo',
				'dsn'=>'mysql:dbname=test;host=localhost',
				'driver_options'=>array(
						PDO::MYSQL_ATTR_INIT_COMMAND=>'SET NAMES \'UTF8\''
				),
		),
    
		'service_manager'=>array(
				'factories'=>array(
						'Zend\Db\Adapter\Adapter'=>'Zend\Db\Adapter\AdapterServiceFactory',
				    
				)
		),

    
    
);

二、数据库帐号配置 local.php

return array(

    'db'=>array(
    		'username'=>'test',
    		'password'=>'test',
    ),
 
);

三、统一分页 路由配置及主要路由控制配置

    'router' => array(
    		'routes' => array(
    		    //分页
    		    'paginator' => array(
    		    		'type' => 'segment',
    		    		'options' => array(
    		    				'route' => '[page/:page]',
    		    				'defaults' => array(
    		    	
    		    						'page' => 1,
    		    				),
    		    		
    		    		),
    		    ),
                               //主要路由控制
    				'test' => array(
    						'type'    => 'Segment',
    						'options' => array(
    								'route'    => '/test[/:controller[/:action][/:id]]',
    								'defaults' => array(
    										'__NAMESPACE__' => 'Test\Controller',
    										'controller'    => 'Index',
    										'action'        => 'index',
    								),
    								'constraints' => array(
    										'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
    								    'id'=>'[0-9]*',
    						
    								),
    						),
    				),
    		),
    ),

四、导航配置

'navigation' => array(
         'default' => array(
             array(
                 'label' => 'access records',
                 'route' => null,
                 'controller'=>'record',
                // 'resource'=>'mvc:re',
          /*        'pages' => array(
                 		array(
                 				'label' => 'Add',
                 		    
                 				'route' => null,
                 		    'controller'=>'manage',
                 				'action' => 'add',
                 		),
                 ), */
             ),
          
             
         ),
     ),

五、Session配置

    'session' => array(
    		'config' => array(
    				'class' => 'Zend\Session\Config\SessionConfig',
    				'options' => array(
    						'name' => 'testname',
    						'remember_me_seconds'=>6000,
    						'cache_expire'=>6000,
    						'gc_maxlifetime'=>6000,
    						'cookie_lifetime'=>6000,
    						'use_cookies' => true,
    						'cookie_httponly' => true,
    							
    
    
    
    				),
    		),
    		'storage' => 'Zend\Session\Storage\SessionArrayStorage',
    		'validators' => array(
    				'Zend\Session\Validator\RemoteAddr',
    				'Zend\Session\Validator\HttpUserAgent',
    		),
    ),

六、Module.php 不同模块配置不同的layout

    //配置不同的layout
    public function init(\Zend\ModuleManager\ModuleManager $moduleManager)
    {
    	$sharedEvents = $moduleManager
    	->getEventManager()->getSharedManager();
    	$sharedEvents->attach(
    			array(
    			    'Test\Controller\IndexController',

    			    
    	),
    			'dispatch',
    			function($e) {
    				$controller = $e->getTarget();
    				$controller->layout('layout/admin');
    			},100
    	);
    }

注:上面的配置 在 zend framework 官网文档都能找到。

本文出自 “凹凸曼” 博客,请务必保留此出处http://www.apoyl.com/?p=1801

日志信息 »

该日志于2014-08-05 18:33由 凹凸曼 发表在PHP分类下, 评论已关闭。

目前盖楼

抱歉,评论被关闭

« »