因我版本没找对,那些方法对应的版本太老,我对下面的方法做了一调整,把重复的不合理的,去掉了一部分,我也是刚学 zendframework,说不了太多,不过按照下面的做就对啦
误的地方。 档名.htaccess而不会发生错误。 架构做出来了。 2. 项目的目录结构 网页的根目录应指向上述目录结构中的 html 文件夹。 4. 重写规则 编辑 html/.htaccess 文件,加入下面两行: RewriteEngine on RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php 注意:上述是针对 apache 的配置。如果是其他的服务器,请参考这里。 5. 引导程序 编辑 html/index.php 文件,敲入下面代码: <?php require_once 'Zend/Controller/Front.php'; $rootPath = dirname(dirname(__FILE__)); Zend_Controller_Front::run($rootPath . '/application/controllers');上面代码的作用是实例化前端控制器(Front Controller)并运行它。6. 默认的动作控制器(Action Controller) Zend Framework 的默认路由规则是 http://域名/控制器名/动作(方法)名。例如: http:///user/show 会被解析到名为 User 的控制器以及该控制器中定义的 show 方法。如果该方法没有定义,则默认 转到 index 方法。 注意:在代码中,控制器名的后面要加上 Controller,而动作名的后面要加上 Action。 编辑 application/controllers/IndexController.php 文件,输入: <?php /** Zend_Controller_Action */ require_once 'Zend/Controller/Action.php'; class IndexController extends Zend_Controller_Action { public function indexAction() { } } 7. 视图(页面)脚本 编辑 application/views/scripts/index/index.phtml,输入: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www./TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-Type" c /> <title>My first Zend Framework App</title> </head> <body> <h1>Hello, World!</h1> </body> </html>8. 错误控制器 默认情况下,Zend Framework 的错误处理插件是被注册的。它需要一个错误控制器来处理错误。缺省的错误控制处理被假定为 ErrorController 以及其中定义的 errorAction。 编辑 application/controllers/ErrorController.php,输入: <?php /** Zend_Controller_Action */ require_once 'Zend/Controller/Action.php'; class ErrorController extends Zend_Controller_Action { public function errorAction() { } } 下面是对应的视图脚本。编辑 application/views/scripts/error/error.phtml,输入: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www./TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-Type" c /> <title>Error</title> </head> <body> <h1>An error occurred</h1> <p>An error occurred; please try again later.</p> </body> </html>9. 运行 好,现在运行网站。在浏览器中键入下面三个地址,得到的结果应该是一样的——就是最最常见的“Hello, World!“。 http://域名 |
|