看板 PHP 關於我們 聯絡資訊
我想透過 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