作者DarkKiller (System hacked)
看板PHP
标题问 Zend Framework 里 Zend_Controller 的用法
时间Thu Feb 21 15:51:47 2008
我想透过 Zend_Controller 做这样的功能:
http://host/ -> IndexController 的 indexAction
http://host/test -> IndexController 的 testAction
不过我写了老半天发现还是不行,上来问看看有没有在用 Zend Framework
的人可以请教。
我先把 1.0.3 的 tarball 解开:
$ ls -al
drwxr-xr-x 5 root www 4096 Feb 21 12:21 ./
drwxr-xr-x 4 root www 4096 Feb 20 03:10 ../
drwxrwxr-x 5 root www 4096 Nov 29 06:03 ZendFramework-1.0.3/
然後开始写 index.php:
<?php
function mymain()
{
set_include_path(get_include_path() . ':' . dirname(__FILE__) . '/ZendFramework-1.0.3/library');
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
$c = Zend_Controller_Front::getInstance();
$c->setParam('noViewRenderer', TRUE);
$c->addControllerDirectory(dirname(__FILE__) . '/controllers');
$c->dispatch();
}
mymain();
?>
然後开 controllers 的目录写 IndexController.php:
<?php
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
print_r($this->_request);
echo "[[[index]]]\n";
}
public function testAction()
{
print_r($this->_request);
echo "[[[test]]]\n";
}
}
?>
以及 ErrorController.php:
<?php
class ErrorController extends Zend_Controller_Action
{
public function errorAction()
{
print_r($this->_request);
echo "[[[error]]]\n";
}
}
?>
最後设定 .htaccess,把所有东西都丢给 index.php:
#
RewriteEngine On
RewriteBase /
RewriteRule .* index.php [L]
所以,目前的目录架构是:
$ ls -al
drwxr-xr-x 5 root www 4096 Feb 21 12:21 ./
drwxr-xr-x 4 root www 4096 Feb 20 03:10 ../
-rw-r--r-- 1 root www 62 Feb 19 17:16 .htaccess
drwxrwxr-x 5 root www 4096 Nov 29 06:03 ZendFramework-1.0.3/
drwxr-xr-x 2 root www 4096 Feb 21 11:11 controllers/
-rw-r--r-- 1 root www 426 Feb 21 11:11 index.php
$ ls -al controllers
drwxr-xr-x 2 root www 4096 Feb 21 11:11 ./
drwxr-xr-x 5 root www 4096 Feb 21 12:21 ../
-rw-r--r-- 1 root www 165 Feb 21 11:11 ErrorController.php
-rw-r--r-- 1 root www 261 Feb 21 11:04 IndexController.php
在
http://host/ 总是会出现 [[[error]]],我想问看看有没有漏掉什麽?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.54.119