// Twitter Model
class Twitter {
public function getRecentTweets() {}
.....
.....
}
IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$twitter = new Twitter();
$this->view->tweets = $twitter->getRecentTweets();
}
}
On Mon, Apr 20, 2009 at 3:03 PM, Ryan Hagan <ryan@ryanhagan.net> wrote:
Hello,
I'm trying to figure out the best way to handle slightly (very
slightly) complex views with Zend and constantly running into a road
block. I'm hoping you guys can help guide me down the right path
here.
Basically, I have several elements that get used in different parts of
the system in different ways. The elements are things like Twitter
updates, blog posts, current media, etc. Each element has its own
view script which I want to include at higher levels. For instance,
twitter updates get displayed in different places on my index page
than they do on my dedicated Twitter page, but the basic view is the
same in all cases. It's the layout that is different.
Here is some pseudo-code. I'm primarily concerned with how to handle
the view aggregation from the controller side.
TwitterController extends Zend_Controller_Action
{
public function recentAction()
{
$this->view->headLink()->appendStylesheet('css/twitter.css');
$twitter = new Zend_Service_Twitter('username','password');
$this->view->tweets = $twitter->status->userTimeLine('me');
}
}
recent.phtml
<?php foreach ($this->tweets as $tweet) { ?>
<div class="tweet">
<p><?= $tweet->text ?></p><br/>
<em>via <?= $tweet->source ?></em>
</div>
<?php } ?>
IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$this->_helper->actionStack('recent', 'twitter');
$this->_helper->actionStack('curmonth', 'blog');
$this->_helper->actionStack('curlistening', 'media');
$this->_helper->actionStack('curwatching', 'media');
$this->_helper->actionStack('curreading', 'media');
}
}
index.phtml
<div id="blog-col">
<?= $this->blog ?>
</div>
<div id="whatnow-col">
<?= $this->tweets ?>
<?= $this->songs ?>
<?= $this->shows ?>
<?= $this->books ?>
</div>
Obviously, actionStack doesn't work like I want it to. What I would
REALLY like, is something along these lines...
IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$this->view->tweets = $this->_helper->actionStack('recent', 'twitter');
$this->view->blog = $this->_helper->actionStack('curmonth', 'blog');
$this->view->songs =
$this->_helper->actionStack('curlistening', 'media');
$this->view->shows =
$this->_helper->actionStack('curwatching', 'media');
$this->view->books = $this->_helper->actionStack('curreading', 'media');
}
}
Thank you!!
--
Ryan Hagan
ryan@ryanhagan.net
--
Cory Wiles
kwylez@gmail.com
http://www.corywiles.com/
http://www.randomthoughtprocess.com/
没有评论:
发表评论