Zend Framework

since 2011-02-03

PHP のアプリケーションフレームワークの一つ。

やってみた

ZendFramework-1.11.3-minimal によると PHP 5.2.4 以降が必要。

.htaccess

RewriteEngine On
RewriteRule !\.(js|ico|gif|jpg|png|css|zip|gz)$ index.php
RewriteBase /zendframework/ZendApp
DirectoryIndex index.php

apache の rewrite を使用する。

最初のルールは拡張子がパターンに当てはまらないものを index.php に書き換える。

index.php

<?php
set_include_path('c:/htdocs/zendframework/library');
require_once 'Zend/Controller/Front.php';
Zend_Controller_Front::run('controllers');
//require_once 'Zend/Version.php'; 
//echo Zend_Version::VERSION; 

下の2行を有効にすると localhost/zendframework/ZendApp/index で 1.11.3 という出力が得られた。

controllers/IndexController.php

<?php
require_once 'Zend/Controller/Action.php';
class IndexController extends Zend_Controller_Action
{
    public function init()
    {
        /* Initialize action controller here */
    }
 
    public function indexAction()
    {
	$req = $this->getRequest();
	$co = $req->getControllerName();
	$ac = $req->getActionName();
	$this->view->assign('day', $req->getParam('day') );
	$this->view->assign('co', $co);
	$this->view->assign('ac', $ac);
	$this->view->assign('val', '<12345>');
        echo $this->render();
    }
}

views/scripts/index/index.phtml

<pre>
<?php 
echo 'hello' . PHP_EOL;
echo $this->escape( $this->val ) . PHP_EOL;
echo $this->escape( $this->co ) . PHP_EOL;
echo $this->escape( $this->ac ) . PHP_EOL;
echo $this->escape( $this->day ) . PHP_EOL;
?>
</pre>

出力

localhost/zendframework/ZendApp/index/index/day/25

を叩くと

hello
<12345>
index
index
25

が得られた。

資料


PHPフレームワーク Zend Framework入門
藤野 真吾
ソーテック社
売り上げランキング: 26432

PHPフレームワーク完全マスター
佐久嶋 ひろみ
メディアテック出版
売り上げランキング: 332136

zendframework.txt · 最終更新: 2011/02/03 23:17 by Takuya Nishimoto
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0