Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1261738
  • 博文数量: 315
  • 博客积分: 10397
  • 博客等级: 上将
  • 技术积分: 3731
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-07 21:21
文章分类

全部博文(315)

文章存档

2015年(10)

2014年(3)

2013年(2)

2012年(8)

2011年(8)

2010年(29)

2009年(59)

2008年(77)

2007年(119)

分类:

2008-01-09 16:07:25


Zend_Controller_Action_Helper_View 为我们初始化视图属性($this->view)并且也调用一
个视图脚本。对于调用,它设置Zend_View 对象去查找views/scripts/{controller name},以便视
图脚本被调用,并且将(缺省,至少)调用名称为在action 之后带有phtml 扩展名的脚本。就
这样,被调用视图脚本是 views/scripts/{controller name}/{action_name}.phtml 并且被呈递的
内容被追加到响应对象的body 里。响应对象用来把所有的HTTP 头,body content 和MVC
系统产生的异常放在一起。前端控制器接着自动地发送头以及紧接着的在dispatch 尾端的
body 内容。
//使用一个模型来获取书籍作者和标题相关数据
$data = array(
    array(
        
'author' => 'Hernando de Soto',
        
'title' => 'The Mystery of Capitalism'
    
),
    array(
        
'author' => 'Henry Hazlitt',
        
'title' => 'Economics in One Lesson'
    
),
    array(
        
'author' => 'Milton Friedman',
        
'title' => 'Free to Choose'
    
)
);

//传递数据给Zend_View类的实例 
Zend_Loader::loadClass('Zend_View');
$view = new Zend_View();
$view->books $data;

//调用一段View代码"booklist.php"来显示数据
echo $view->render('booklist.php');
 
另一个较高自动化的例子:
   Zend_Loader::loadClass('Zend_Feed');
   // 取得最新的 Slashdot 头条新闻
   try {   
    $slashdotRss = Zend_Feed::import('');
    }
   catch (Zend_Feed_Exception $e)
    {   
     // feed 导入失败   
     echo "Exception caught importing feed: {$e->getMessage()}\n";    exit;
    }
    // 初始化保存 channel 数据的数组
    $channel = array(   
     'title'       => $slashdotRss->title(),   
     'link'        => $slashdotRss->link(),   
     'description' => $slashdotRss->description(),   
     'items'       => array()   
     );
     // 循环获得channel的item并存储到相关数组中
     foreach ($slashdotRss as $item) {   
      $channel['items'][] = array(       
       'title'       => $item->title(),       
       'link'        => $item->link(),       
       'description' => $item->description()       
       );
     }
     $this->view->rss=$channel['items'];
阅读(1534) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~