Zend Framework 2 wiki 介紹
簡單說,這個框架是一個以 MVC 為基礎的框架,MVC 在這篇已經超出範圍,所以不在這裡去贅述,有興趣可以去找找資料
線上文件連結:http://zf2.readthedocs.io/en/latest/index.html
使用 Composer 下載 Zend Framework
1 2 3 4 5 6 7 8 9 | #下載 Composer curl -sS https: //getcomposer .org /installer | /path/to/executable/php #執行 composer.phar 產生一個 Zend Framework 的 skeleton application 專案 php composer.phar create-project --stability= "dev" zendframework /skeleton-application path /to/install |
從上面可以得知,下載完之後的專案為一個正在開發的 skeleton 骨架 application
在這篇的文章中,會請你去設定 Apache 的 VirtualHost 去更改網址,如不要的話,或是有一些共享主機 (shared hosting) 並不允許你去更改 httpd.conf 的設定,所以這在部署上顯得較為困難,因此,如不改的話,其實可以連上 http://your-domain.com/project-name/public 就會看到下面有著與文件上一模一樣的截圖,有出現一模一樣的截圖就代表設定成功了。
可以試著測試預設的 route 有沒有正常的運作試著輸入網址:http://your-domain.com/project-name/public/123 就會出現下面的 404 Not found
Error reporting
可以編輯 public 目錄下的 index.php 裡面的第四行插入下面這段 code:
其目的是在開發的階段可以立即的在網頁上顯示錯誤,不過記得網站上線之後要將錯誤關閉
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <?php /** * Display all errors when APPLICATION_ENV is development. (這段是插入的) */ if ( $_SERVER [ 'APPLICATION_ENV' ] == 'development' ) { error_reporting (E_ALL); ini_set ( "display_errors" , 1); } /** * This makes our life easier when dealing with paths. Everything is relative * to the application root now. */ chdir (dirname(__DIR__)); // Decline static file requests back to the PHP built-in webserver if (php_sapi_name() === 'cli-server' && is_file (__DIR__ . parse_url ( $_SERVER [ 'REQUEST_URI' ], PHP_URL_PATH))) { return false; } // Setup autoloading require 'init_autoloader.php' ; // Run the application! Zend\Mvc\Application::init( require 'config/application.config.php' )->run(); |
下一篇介紹如何建立一個自己的 Module