Zend Framework2.0 を試してみる(2)
昨日の続き。
とりあえずチュートリアルにある Quickstart をやってみる。
Create Your Project
まずはプロジェクトを作る。
とりあえず、clone した所に作ってみる。
$ bin/zf.php create project quickstart Creating project at /var/php/zf2/zf/quickstart Note: This command created a web project, for more information setting up your VHOST, please see docs/README
ちゃんと出来た。
とりあえず Virtualhost をいじって、表示できるか確認してみる。
アクセスすると 以下のようにエラーが表示。
Fatal error: Class 'Zend_Application' not found in /var/php/zf2/zf/quickstart/public/index.php on line 21
index.php を見てみる。
<?php require_once 'Zend/Application.php'; // Create application, bootstrap, and run $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' );
require_once 先と、クラス名が違っているので直す。
--- index.php.orig 2010-07-24 22:09:45.000000000 +0900 +++ index.php 2010-07-24 22:10:58.000000000 +0900 @@ -15,10 +15,10 @@ ))); /** Zend_Application */ -require_once 'Zend/Application.php'; +require_once 'Zend/Application/Application.php'; // Create application, bootstrap, and run -$application = new Zend_Application( +$application = new Zend\Application\Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' );
改めてブラウザでアクセスしてみる。
Warning: include_once(Zend/Application/Bootstrap/Bootstrap.php) [function.include-once]: failed to open stream: No such file or directory in /var/php/zf2/zf/library/Zend/Loader.php on line 151
Bootstrap が読めないとエラー。
quickstart/application/Bootstrap.php を修正する。
$ diff -u Bootstrap.php.orig Bootstrap.php --- Bootstrap.php.orig 2010-07-24 22:12:47.000000000 +0900 +++ Bootstrap.php 2010-07-24 22:13:05.000000000 +0900 @@ -1,6 +1,6 @@ <?php -class Bootstrap extends Zend_Application_Bootstrap_Bootstrap +class Bootstrap extends Zend\Application\Bootstrap {
再度ブラウザでアクセスすると、今度はエラーもなく正しく読み込めた。
Create A Layout
続いて Layout を作ってみる。
$ php bin/zf.php enable layout Warning: include_once(Zend/Tool/Project/Profile/Resource/Resource.php): failed to open stream: No such file or directory in /var/php/zf2/zf/library/Zend/Loader.php on line 151
Resource.php が読めないらしい。
呼び出しもとは、library/Zend/Tool/Project/Profile/Resource/Container.php なのでこれを修正する。
--- Container.php.orig 2010-07-24 00:22:40.000000000 +0900 +++ Container.php 2010-07-24 16:27:57.000000000 +0900 @@ -184,7 +184,7 @@ throw new Profile\Exception('Context must be of type string or Zend_Tool_Project_Context_Interface.'); } - $newResource = new Resource($context); + $newResource = new Profile\Resource($context); if ($attributes) { $newResource->setAttributes($attributes);
試してみる。
$ php bin/zf.php enable layout Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING in /var/php/zf2/zf/library/Zend/Tool/Project/Profile/Iterator/ContextFilter.php on line 186
シンタックスエラー…だと…?
<?php if ($currentItem->getContent() instanceof \$acceptType) {
なるほどー。修正修正。
--- ContextFilter.php.orig 2010-07-24 16:25:23.000000000 +0900 +++ ContextFilter.php 2010-07-24 22:53:12.000000000 +0900 @@ -183,13 +183,13 @@ } foreach ($this->_acceptTypes as $acceptType) { - if ($currentItem->getContent() instanceof \$acceptType) { + if ($currentItem->getContent() instanceof $acceptType) { return true; } } foreach ($this->_denyTypes as $denyType) { - if ($currentItem->getContext() instanceof \$denyType) { + if ($currentItem->getContext() instanceof $denyType) { return false; } }
試してみる。
$ php bin/zf.php enable layout Layouts have been enabled, and a default layout created at /var/php/zf2/zf/quickstart/application/layouts/scripts/layout.phtml A layout entry has been added to the application config file. $ tree quickstart/application/layouts layouts `-- scripts `-- layout.phtml
ちゃんと出来た。
引き続きチュートリアルにそってやってみる。
application/configs/application.ini に以下を追加するよう。
resources.view[] =
続いて application/Bootstrap.php に _initDoctype() を追加する。
<?php class Bootstrap extends Zend\Application\Bootstrap { protected function _initDoctype() { $this->bootstrap('view'); $view = $this->getResource('view'); $view->doctype('XHTML1_STRICT'); } }
application/layouts/scripts/layout.phtml に以下を追加。
<?php echo $this->doctype() ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Zend Framework Quickstart Application</title> <?php echo $this->headLink()->appendStylesheet('/css/global.css') ?> </head> <body> <div id="header" style="background-color: #EEEEEE; height: 30px;"> <div id="header-logo" style="float: left"> <b>ZF Quickstart Application</b> </div> <div id="header-navigation" style="float: right"> <a href="<?php echo $this->url( array('controller'=>'guestbook'), 'default', true) ?>">Guestbook</a> </div> </div> <?php echo $this->layout()->content ?> </body> </html>
ブラウザでアクセスし、ソースを見てみる。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
とりあえずブラウザでアクセスして layout を表示できる所まではできたが、Zend_Tool がジェネレートするのはまだ 1.1x 系なのかねー。