这是我的第一堂课
<?php
namespace Config\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Config\Model\Config;
use Config\Form\ConfigForm;
class ConfigController extends AbstractActionController
{
protected $configTable;
public function indexAction()
{
$this->getSMTPConfigTable();
return new ViewModel(array(
'config' => $this->getConfigTable()->fetchAll(),
));
}
public function addAction()
{
$form = new ConfigForm();
$form->get('submit')->setValue('Add');
$request = $this->getRequest();
if ($request->isPost()) {
$config = new Config();
$form->setInputFilter($config->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$config->exchangeArray($form->getData());
$this->getConfigTable()->saveConfig($config);
return $this->redirect()->toRoute('zfcadmin/config');
}
}
return array('form' => $form);
}
public function editAction()
{
$id = (int) $this->params()->fromRoute('id', 0);
if (!$id) {
return $this->redirect()->toRoute('zfcadmin/config', array(
'action' => 'add'
));
}
try {
$config = $this->getConfigTable()->getConfig($id);
}
catch (\Exception $ex) {
return $this->redirect()->toRoute('zfcadmin/config', array(
'action' => 'index'
));
}
$form = new ConfigForm();
$form->bind($config);
$form->get('submit')->setAttribute('value', 'Edit');
$request = $this->getRequest();
if ($request->isPost()) {
$form->setInputFilter($config->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$this->getConfigTable()->saveConfig($form->getData());
return $this->redirect()->toRoute('zfcadmin/config');
}
}
return array(
'id' => $id,
'form' => $form,
);
}
public function getConfigTable()
{
if (!$this->configTable) {
$sm = $this->getServiceLocator();
$this->configTable = $sm->get('Config\Model\ConfigTable');
}
return $this->configTable;
}
public function getSMTPConfigTable()
{
$pr=$this->getConfigTable()->fetchAll();
return $pr;
}
}
在另一个模块类中我该怎么做?我尝试了大多数方法,但我失败了,请帮助我。(对不起我的英语)我需要 $temp=new ConfigController(); $temp->getSMTPConfigTable();