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

が得られた。

資料

<html> <hr /> <div class="amazlet-box" style="margin-bottom:0px;"><div class="amazlet-image" style="float:left;margin:0px 12px 1px 0px;"><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4881665936/r4wh-22/ref=nosim/" name="amazletlink" target="_blank"><img src="http://ecx.images-amazon.com/images/I/41SpJt6fRGL._SL160_.jpg" alt="PHPフレームワーク Zend Framework入門" style="border: none;" /></a></div><div class="amazlet-info" style="line-height:120%; margin-bottom: 10px"><div class="amazlet-name" style="margin-bottom:10px;line-height:120%"><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4881665936/r4wh-22/ref=nosim/" name="amazletlink" target="_blank">PHPフレームワーク Zend Framework入門</a><div class="amazlet-powered-date" style="font-size:80%;margin-top:5px;line-height:120%">posted with <a href="http://www.amazlet.com/browse/ASIN/4881665936/r4wh-22/ref=nosim/" title="PHPフレームワーク Zend Framework入門" target="_blank">amazlet</a> at 11.02.03</div></div><div class="amazlet-detail">藤野 真吾 <br />ソーテック社 <br />売り上げランキング: 26432<br /></div><div class="amazlet-sub-info" style="float: left;"><div class="amazlet-link" style="margin-top: 5px"><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4881665936/r4wh-22/ref=nosim/" name="amazletlink" target="_blank">Amazon.co.jp で詳細を見る</a></div></div></div><div class="amazlet-footer" style="clear: left"></div></div>

<hr />

<div class="amazlet-box" style="margin-bottom:0px;"><div class="amazlet-image" style="float:left;margin:0px 12px 1px 0px;"><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4896273567/r4wh-22/ref=nosim/" name="amazletlink" target="_blank"><img src="http://ecx.images-amazon.com/images/I/51JJUJ-TXzL._SL160_.jpg" alt="PHPフレームワーク完全マスター" style="border: none;" /></a></div><div class="amazlet-info" style="line-height:120%; margin-bottom: 10px"><div class="amazlet-name" style="margin-bottom:10px;line-height:120%"><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4896273567/r4wh-22/ref=nosim/" name="amazletlink" target="_blank">PHPフレームワーク完全マスター</a><div class="amazlet-powered-date" style="font-size:80%;margin-top:5px;line-height:120%">posted with <a href="http://www.amazlet.com/browse/ASIN/4896273567/r4wh-22/ref=nosim/" title="PHPフレームワーク完全マスター" target="_blank">amazlet</a> at 11.02.03</div></div><div class="amazlet-detail">佐久嶋 ひろみ <br />メディアテック出版 <br />売り上げランキング: 332136<br /></div><div class="amazlet-sub-info" style="float: left;"><div class="amazlet-link" style="margin-top: 5px"><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4896273567/r4wh-22/ref=nosim/" name="amazletlink" target="_blank">Amazon.co.jp で詳細を見る</a></div></div></div><div class="amazlet-footer" style="clear: left"></div></div> </html>

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