我正在关注本教程:Zend Framework 1.11 入门
http://akrabat.com/wp-content/uploads/Getting-Started-with-Zend-Framework.pdf
,第 12 页,“列出专辑”
D:\program files (x86)\Zend\Apache2\htdocs\zf-tutorial\application\models\DbTable\Albums.php
<?php class Application_Model_DbTable_Albums extends Zend_Db_Table_Abstract { protected $_name = 'albums'; public function getAlbum($id) { ... } public function addAlbum($artist, $title) { ... } public function updateAlbum($id, $artist, $title) { ... } public function deleteAlbum($id) { ... } }
D:\program files (x86)\Zend\Apache2\htdocs\zf-tutorial\application\controllers\IndexController.php
<?php class IndexController extends Zend_Controller_Action { public function indexAction() $albums = new Application_Model_DbTable_Albums(); $this->view->albums = $albums->fetchAll(); } }
D:\program files (x86)\Zend\Apache2\htdocs\zf-tutorial\application\views\scripts\index\index.phtml
<?php $this->title = "My Albums"; $this->headTitle($this->title); ?> <p><a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'add'));?>">Add new album</a></p> <table> <tr> <th>Title</th> <th>Artist</th> <th> </th> </tr> <?php foreach($this->albums as $album) : ?> <tr> <td><?php echo $this->escape($album->title);?></td> <td><?php echo $this->escape($album->artist);?></td> <td> <a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'edit', 'id'=>$album->id));?>">Edit</a> <a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'delete', 'id'=>$album->id));?>">Delete</a> </td> </tr> <?php endforeach; ?> </table>
问题:
Albums.php,为什么我们需要这个:
protected $_name = 'albums';
?索引控制器.php
一个。
$albums = new Application_Model_DbTable_Albums();
我们没有使用 include/require "Albums.php",我们怎么能使用这个类:Application_Model_DbTable_Albums
?湾。
$this->view->albums = $albums->fetchAll();
这是什么意思:$this->view->albums
?为什么不使用$this->albums
?索引.phtml
一个。
$this->url(array('controller'=>'index','action'=>'add'))
,我在哪里可以检查这个方法:$this->url()
?湾。为什么我们
foreach($this->albums as $album)
在这里使用?不像$this->view->albums
在 IndexController.php 中那样?