【发布时间】:2011-12-01 20:34:50
【问题描述】:
在 IndexController 的 indexAction() 方法中,我调用了模型的方法,该方法从数据库返回员工列表(employeeList)。然后将此员工列表添加到 $view 中,然后调用 $view->render('index. phtml') 和 index .phtml 显示了employeeList。代码如下:
IndexController.php
<?php
require_once('../Zend/Controller/Action.php');
require_once('../models/HRModel.php');
require_once('../Zend/View.php');
class IndexController extends Zend_Controller_Action
{
protected $hrModel;
public function init()
{
$this->hrModel = new Application_Model_HRModel();
}
public function indexAction()
{
$view = new Zend_View(array('scriptPath' =>'../views'));
$view->employeeList = $this->hrModel->queryAllEmployees();
echo $view->render('index.phtml');
}
}
Application_model_HRModel.php
<?php
require_once('Zend/Db.php');
require_once('Zend/Config/Ini.php');
class Application_Model_HRModel
{
protected $db=null;
public function queryAllEmployees() {
return $this->db->fetchAssoc("select comment from guestbook");
}
}
index.phtml
foreach ($this->employeeList as $emp):
extract($emp);
echo '$EMPLOYEE_ID';
echo $comment;
endforeach
现在我想从 indexAction() 方法开始执行。但是怎么做呢?在浏览器中输入的 url 应该是什么?在请求参数中,控制器将是 IndexController,动作将是 indexAction。所以请帮助我来解决这个问题。
【问题讨论】:
-
你在哪里设置文档根ZF?
-
在我的项目中,在应用程序文件夹中有 4 个文件夹,分别命名为 configs、controllers、models、views。在 library 文件夹中,我包含 Zend 文件夹,其中包含 Zend 框架的所有类。因为我必须从索引控制器所以我将 web 根设置为应用程序/控制器,并在运行配置中将项目 url 设置为localhost:8888/Index/index,其中控制器是索引,操作是索引。当我在浏览器中运行它时,它显示为“警告:require_once(../Zend/ Controller/Action.php) [function.require-once]: 无法打开流:
-
您必须将文档根目录设置为公共目录并转到页面:
localhost:8888,但我建议您阅读此内容:framework.zend.com/manual/en/learning.html -
感谢您的回复。我现在已设置为 application/public。但仍然出现同样的问题。我也已在 apache httpd 中设置了文档根目录并且我已阅读您提供的手册并应用了所有内容,但......
标签: zend-framework