从ZEND Framework的IndexController中的indexAction()开始执行(Start execution from indexAction() in IndexController in ZEND Framework)
在IndexController的indexAction()方法中,我调用了模型方法,该方法从数据库返回雇员列表(employeeList)。然后将此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应该是什么?在request参数中,控制器将是IndexController,action将是indexAction.So请帮我解决这个问题。
In indexAction() method of IndexController I have called the method of model which returns the list of employees(employeeList) from database.And then add this this employeeList to $view and then call $view->render('index.phtml') and index .phtml shows the employeeList.The code is ad follows:
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
Now I want to start the execution from indexAction() method.But how to do this?What should be the url to be entered in browser?In request parameter the controller will be IndexController and action will be indexAction.So Kindly help me in resolving this issue.
原文:https://stackoverflow.com/questions/8341284