程式CODE

2015年7月20日 星期一

zend framework2研習

一、安裝composer
http://www.arthurtoday.com/2013/01/ubuntu-install-php-composer.html
    最後記得sudo mv composer.phar composer 改名

二、安裝git
    sudo apt-get install git

三、安裝zend framework 2
    sudo composer create-project -n -sdev zendframework/skeleton-application /home/webadmin/html/www

四、安裝zftool
sudo composer require zendframework/zftool
五、建立模組 
sudo vendor/bin/zf.php create module Cms

六、建立IndexController 
sudo vendor/bin/zf.php create controller Index Cms

七、配置module.config.php 
<?php
return array(
    'router' => array(
        'routes' => array(
            'cms' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/cms',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Cms\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    'controllers' => array(
        'invokables' => array(
            'Cms\Controller\Index' => 'Cms\Controller\IndexController'
        ),
    ),
    'view_manager' => array(

        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
    ),
);

八、新增一頁page
vendor\bin\zf.php.bat create controller Page Cms

九、修改module.config.php
    'controllers' => array(
        'invokables' => array(
            'Cms\Controller\Index' => 'Cms\Controller\IndexController',
            'Cms\Controller\Page' => 'Cms\Controller\PageController',
        ),

十、改樣版引擎為twig
 在專案根目錄下
composer require zf-commons/zfc-twig

在 application.config.php 加入 ZfcTwig:
  在./config/application.config.php裡面
  在modules=>array('先前的','ZfcTwig')

layout 改用 layout.twig
  複製vendor/zf-commons/zfc-twig/examples/layout/layout.twig
  貼在./module/Application/view/layout/ 內

十一、twig的練習
   在新模組的view/index/下, 新增一個index.twig
  內容為:
  {% extends "layout/layout.twig" %}
  {% block title %}{{ parent() }}新的title{% endblock %}
  {% block content %}新的content{% endblock %}

  語法參考:http://twig.sensiolabs.org/doc/tags/extends.html


十二、apache的加入
1.安裝doctrine
在composer.json加入
(1)"doctrine/common":^2.5","doctrine/migrations":"dev-master","zf-commons/zfc-user-doctrine-orm":"",





沒有留言:

張貼留言