zend framework2流程分析

入口文件在 htdocs\index.php

访问:

http://www.test3.com/album

http://www.test3.com/album/edit/1

 

配置文件在

config\autoload\global.phplocal.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();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值