在控制器 MVC 中初始化对象
Initialize object in controller MVC
我正在按照本教程从头开始使用 MVC 进行实验,并在尝试从控制器初始化新对象时遇到 500 个错误。
http://www.phpro.org/tutorials/Model-View-Controller-MVC.html
employeelist.class.php
<?php
class employeelist
{
private $employees = array();
public function getEmployees() {
sql='SELECT F0101.ABAN8, F0101.ABALPH FROM F0101 INNER JOIN FP0102 ON F0101.ABAN8=FP0102.VEAN8 WHERE FP0102.VESTAT=''';
$stmt= db2_prepare($this->connection,$sql);
$result= db2_execute($stmt);
while ($row = db2_fetch_assoc($stmt)) {
$employees = array($row['ABAN8'],$row['ABALPH'])
}
return array($employees);
}
}
?>
employeelistController.php
class employeelistController Extends baseController {
public function index() {
$registry->employeelist = new employeelist;
$this->registry->template->employeelist = $registry->employeelist->getEmployees();
$this->registry->template->show('employeelist_index');
}
}
?>
employeelist_index.php
<?php include('includes/header.php'); ?>
<div class="row">
<?php include('includes/accounting-menu.php'); ?>
<div class="col-md-9">
<div class="row">
<ul class="nav nav-pills">
<li role="presentation" class="active"><a href="/commissions/index">Επισκόπηση προμήθειων</a></li>
<li role="presentation"><a href="/commissions/statement">Αναλυτική κατάσταση προμηθειών</a></li>
</ul>
<br/>
</div>
</div>
</div>
<?php include('includes/footer.php'); ?>
在控制器文件中注释掉以下内容时,错误消失
$this->registry->template->employeelist = $registry->employeelist->getEmployees();
$this->registry->template->show('employeelist_index');
很明显,我对如何从控制器中初始化对象有一些误解。有人对如何解决这个问题有任何建议吗?
在文件中 employeelist.class.php
$stmt= db2_prepare($this->connection,$sql);
$this->connection 为空,引用未声明的变量,更新为
$stmt= db2_prepare($this->registry->user->connection,$sql);
我正在按照本教程从头开始使用 MVC 进行实验,并在尝试从控制器初始化新对象时遇到 500 个错误。
http://www.phpro.org/tutorials/Model-View-Controller-MVC.html
employeelist.class.php
<?php
class employeelist
{
private $employees = array();
public function getEmployees() {
sql='SELECT F0101.ABAN8, F0101.ABALPH FROM F0101 INNER JOIN FP0102 ON F0101.ABAN8=FP0102.VEAN8 WHERE FP0102.VESTAT=''';
$stmt= db2_prepare($this->connection,$sql);
$result= db2_execute($stmt);
while ($row = db2_fetch_assoc($stmt)) {
$employees = array($row['ABAN8'],$row['ABALPH'])
}
return array($employees);
}
}
?>
employeelistController.php
class employeelistController Extends baseController {
public function index() {
$registry->employeelist = new employeelist;
$this->registry->template->employeelist = $registry->employeelist->getEmployees();
$this->registry->template->show('employeelist_index');
}
}
?>
employeelist_index.php
<?php include('includes/header.php'); ?>
<div class="row">
<?php include('includes/accounting-menu.php'); ?>
<div class="col-md-9">
<div class="row">
<ul class="nav nav-pills">
<li role="presentation" class="active"><a href="/commissions/index">Επισκόπηση προμήθειων</a></li>
<li role="presentation"><a href="/commissions/statement">Αναλυτική κατάσταση προμηθειών</a></li>
</ul>
<br/>
</div>
</div>
</div>
<?php include('includes/footer.php'); ?>
在控制器文件中注释掉以下内容时,错误消失
$this->registry->template->employeelist = $registry->employeelist->getEmployees();
$this->registry->template->show('employeelist_index');
很明显,我对如何从控制器中初始化对象有一些误解。有人对如何解决这个问题有任何建议吗?
在文件中 employeelist.class.php
$stmt= db2_prepare($this->connection,$sql);
$this->connection 为空,引用未声明的变量,更新为
$stmt= db2_prepare($this->registry->user->connection,$sql);