Zend_Controller
とりあえず動かす
>|php|
<?php
// main
$ctrl = Zend_Controller_Front::getInstance();
$ctrl->setControllerDirectory('app/controllers');
$ctrl->dispatch();
// app/controllers/IndexController.php
class IndexController extends Zend_Controller_Action{
public function indexAction(){
$this->view->assign('time', time());
}
}
// app/controllers/ErrorController.php
class ErrorController extends Zend_Controller_Action{
public function errorAction(){
}
}
// app/views/scripts/index/index.phtmlと
// app/views/scripts/error/error.phtmlも用意しておく
//
?>
||<
エラーを捕捉したい場合
>|php|
<?php
$ctrl->dispatch();
$exceptions = $ctrl->getResponse()->getException();
if ($exceptions){
var_dump(array_shift($exceptions));
}
?>
||<
テンプレートにassignして、出力する
>|php|
<?php
function hogeAction(){
$this->view->assign('time', time();
}
?>
// app/views/scripts/index/hoge.phtml
/*
<html>
<body>
now: <?php echo $this->view->time ?>
</body>
</html>
*/
||<
Zend_Controller_Action
初期化はinit()に書く
$this->viewにデフォルトのViewが入ってる。
履歴
- 第 2 版akkun_choi2008-12-07 09:17:56
- 第 1 版akkun_choi2008-08-13 23:18:51