私はこのチュートリアルに従っています:Getting Started with 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';
?IndexController.php
を。
$albums = new Application_Model_DbTable_Albums();
include/require "Albums.php" を使用しませんでした。このクラスをどのように使用できますApplication_Model_DbTable_Albums
か?b.
$this->view->albums = $albums->fetchAll();
これはどういう意味ですか:$this->view->albums
? なぜ使用しないの$this->albums
ですか?index.phtml
を。
$this->url(array('controller'=>'index','action'=>'add'))
、このメソッドはどこで確認できますか:$this->url()
?b. なぜ
foreach($this->albums as $album)
ここで使用するのですか?$this->view->albums
IndexController.php のようではありませんか?