$this->render(); return; } } }
// redirect back to the album list unless we have rendered the view $this->_redirect('/'); }
...再一次,我们使用同样的计策去检查请求方法来决定我们要显示确认表单还是应该删除。通过Album()类,就像插入和更新,实际的删除动作通过调用Zend_Db_Table::delete()来完成。
注意,我们在设置响应body 后立即返回。这就是为什么我们在函数的最后能重定向到album列表。这样,任何不同的健全的检查失败,我们就返回到album 列表而不需要在这个函数里调用_redirect()多次。 模板是一个简单的表单:
zf-tutorial/application/views/indexDelete.tpl.php复制PHP内容到剪贴板PHP代码: render('header.phtml'); ?>
escape($this->title); ?> album) :?>
baseUrl ?>/index/delete\
Are you sure that you want to delete 'escape($this->album->title); ?>' by 'escape($this->album->artist); ?>'?
album->id; ?>\
Cannot find album.
render('footer.phtml'); ?>故障排除
如果除了index/index 能工作外,你发现其他控制模块不能如你所愿,最有可能的问题是路由不能确定你的网站在那个子目录下。就目前来看,通常发生的情况是你网站的url 不同于web-root 的目录。
如果这个缺省代码不适用,你应该自行设置适合你的服务器的$baseURL 的值:
zf-tutorial/index.php复制PHP内容到剪贴板PHP代码: ...
// setup controller
$frontController = Zend_Controller_Front::getInstance(); $frontController->throwExceptions(true);
$frontController->setBaseUrl('/mysubdir/zf-tutorial');
$frontController->setControllerDirectory('./application/controllers');
...你应当用正确的URL 指向index.php 的路径来替换'/mysubdir/zf-tutorial/'。例如:如果你的指向index.php 的URL 是http://localhost/~ralle/zf_tutorial/index.php,正确的$baseUrl 的值就是'/~ralle/zf_tutorial/'。 结论
本教程使用Zend Framwork 开发了一个简单但功能齐全的MVC 应用例程,我希望你能感兴趣和觉得有用。如果你发现任何错误,请给我发邮件到 rob@akrabat.com! 本教程只涉及到Zend Framework 的最节本的用法,你应该去看看手册(http://framework.zend.com/manual)那里有更多的类可以使用,还有wiki(http://framework.zend.com/wiki) 中更多的内幕 !
16