入口文件在htdocs\index.php 访问: http://www.test3.com/album http://www.test3.com/album/edit/1 配置文件在 config\autoload\global.php和local.php 控制器在 如:module\Album\src\Album\Controller\AlbumController.php 方法名带
入口文件在 htdocs\index.php
访问:
http://www.test3.com/album
http://www.test3.com/album/edit/1
配置文件在
config\autoload\global.php和local.php
控制器在
如:module\Album\src\Album\Controller\AlbumController.php
方法名带Action
如:
// Add content to this method:
public function addAction() {
$form = new AlbumForm();
$form->get('submit')->setValue('Add');
$request = $this->getRequest();
if ($request->isPost()) {
$album = new Album();
$form->setInputFilter($album->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$album->exchangeArray($form->getData());
$this->getAlbumTable()->saveAlbum($album);
// Redirect to list of albums
return $this->redirect()->toRoute('album');
}
}
return array('form' => $form);
}
模型在module\Album\src\Album\Model\AlbumTable.php
如:
class AlbumTable {
protected $tableGateway;
public function __construct(TableGateway $tableGateway) {
$this->tableGateway = $tableGateway;
}
public function fetchAll() {
$resultSet = $this->tableGateway->select();
return $resultSet;
}
public function getAlbum($id) {
$id = (int) $id;
$rowset = $this->tableGateway->select(array('id' => $id));
$row = $rowset->current();
if (!$row) {
throw new \Exception("Could not find row $id");
}
return $row;
}
}
视图在module/Album/view/album/album/edit.phtml
如:
<?php
// module/Album/view/album/album/edit.phtml:
$title = 'Edit album';
$this->headTitle($title);
?>
<h1><?php echo $this->escapeHtml($title); ?></h1>
<?php
$form = $this->form;
$form->setAttribute('action', $this->url('album', array('action' => 'edit','id' => $this->id,)));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('title'));
echo $this->formRow($form->get('artist'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();