续 Zend Framework 多模块配置 (二)
7)控制器文件:
ErrorController.php
class Default_ErrorController extends Zend_Controller_Action
{
public function errorAction() {
//取得错误信息
$errors = $this->_getParam( 'error_handler' );
//取得Log对象
$log = Zend_Registry::get( 'log' );
//把错误信息写入日志文件
$log->emerg( $errors[ 'exception' ]->__toString() );
switch ( $errors->type ) {
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
// 404 错误 -- 控制器或方法没有发现
$this->getResponse()->setHttpResponseCode( 404 );
$this->view->message = 'Page not found';
break;
default:
// application错误
$this->getResponse()->setHttpResponseCode( 500 );
$this->view->message = 'Application error';
break;
}
$this->view->exception = $errors->exception;
$this->view->request = $errors->request;
}
}//end class
IndexController.php
class Default_IndexController extends Zend_Controller_Action
{
public function init() {}
public function indexAction() {
$Albums = new Albums();
$this->view->test = $Albums->fetchAll();
}
}//end class
8)Model文件:
class Albums extends Zend_Db_Table_Abstract
{
protected $_name = 'test';
protected $_primary = 'id';
}//end class
9)视图文件:
repos/application/modules/default/views/layout/default.phtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
<?php echo $this->layout()->content ?>
</body>
</html>
repos/application/modules/default/views/scripts/index/index.phtml
<?php foreach($this->test as $value) : ?>
<span><?php echo $value['id'] ?> - <?php echo $value['name'] ?></span><br >
<?php endforeach ?>
repos/application/modules/default/views/scripts/error/error.phtml
<h1>An error occurred</h1>
<h2><?php echo $this->message ?></h2>
<?php if ('development' == APPLICATION_ENV): ?>
<h3>Exception information:</h3>
<p> <b>Message:</b> <?php echo $this->exception->getMessage() ?></p>
<h3>Stack trace:</h3>
<pre><?php echo $this->exception->getTraceAsString() ?></pre>
<h3>Request Parameters:</h3>
<pre><?php echo var_export($this->request->getParams(), true) ?></pre>
<?php endif ?>
这就是就是一多模块ZF框架配置方法,所以资料都是参考于网上,请先建立一个数据库并把相对应的配置修改下,然后输入你的域名就可以了。
如有什么问题可以留言,谢谢!