Zend框架:在索引视图中包含其他控制器
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

I am new to Zend FW. I am looking to write a simple feedparser in a controller named Feedparsercontroller's indexAction. but i want to display the parsed feed output as a widget on my index page. how can i drive the output/ variable data to my indexview?

The below is my parser.

class FeedparserController extends Zend_Controller_Action {

public function init() {
    /* Initialize action controller here */
}

public function indexAction() {

    $feedUrl = 'http://feeds.feedburner.com/ZendScreencastsVideoTutorialsAboutTheZendPhpFrameworkForDesktop';
    $feed = Zend_Feed_Reader::import ( $feedUrl );

    $this->view->gettingStarted = array ();
    foreach ( $feed as $entry ) {
        if (array_search ( 'Getting Started', $entry->getCategories ()->getValues () )) {
            $this->view->gettingStarted [$entry->getLink ()] = $entry->getTitle ();
        }
    }
}

}

i want to implement the same with my login , register controllers as well.

#0

Perhaps I'm not understanding your question fully.

But, it seems the best approach here would be to create a separate feed controller that is solely responsible for the business logic associated with feeds (retrieving, massaging, setting to view, etc).

Then, create a partial which contains javascript code to call the feed controller, which then outputs the widget you're desiring. This does a few things very well.

  1. It centralizes feed-related logic
  2. It allows you to place the feed widget wherever you want
  3. It is a SOA approach which is generally a good thing

Hope this helps!

#1

I think the best logic with widgets is ajax.

Use some js widgets libraries (maybe jQuery ui for example), then make these widgets be loaded by some ajax queries, returning HTML, this allow you as well simple widgets reloading behviours (without relaoding the whole page).

In the server Side you'll need to allow your controller/Action to be called via ajax requests and to send only html snippets (not a whole page with all the layout).

To do that check ContextSwitch and AjaxContext Action Helpers. You will tell your FeedparserController that the index action can be called with /format/html in an XMLHHTTPRequest, and that in this case the view helper will be index.

In the init part you will say the indexAction can be called in ajax mode, rendering html snippets ('html'):

$Ajaxcontext = $this->_helper->getHelper('AjaxContext');
$Ajaxcontext->addActionContext('index', 'html')
            ->initContext();

Now simply rename your view script feedparser/index.phtml to feedparser/index.ajax.phtml

In the indexAction, do your stuff and output what you want on your view script, do not think about layout composition problems, you're working alone with your own layout part and the composition is done on the js side.

In the javascript part, ensure you're calling via ajax ($.load or $.ajax with jQuery maybe) the url with format/html added as parameters (so http://example.com/feedparser/index/format/html)

Note that in my opinion you should use json responses and not html, maybe json with some html inside. But that's a matter on how you want to control your ajax communication (and handle errors, redirection and such, and it's another subject).

#2

What about a view helper ?

You can read about it View Helpers in Zend Framework

推荐文章

如何在后台运行hg命令(不显示命令提示窗口)?

如何在后台运行hg命令(不显示命令提示窗口)?

推荐文章

由于编译错误,Maven模块无法安装,但将成功编译

由于编译错误,Maven模块无法安装,但将成功编译

推荐文章

PHP、MySQL和JQuery问题?

PHP、MySQL和JQuery问题?

推荐文章

FLEX—如何单击数据网格中的一行并突出显示所有相关行

FLEX—如何单击数据网格中的一行并突出显示所有相关行

推荐文章

在核心数据中跨实体获取和排序

在核心数据中跨实体获取和排序

推荐文章

修复Git存储库中的行尾是否会使将来的“diff”无用

修复Git存储库中的行尾是否会使将来的“diff”无用

推荐文章

用Java记录和轻松查看大量会话数据

用Java记录和轻松查看大量会话数据

推荐文章

Rebol:为什么get access修饰符被调用两次,而它只应该被调用一次

Rebol:为什么get access修饰符被调用两次,而它只应该被调用一次

推荐文章

如何在工具箱中显示数据网格

如何在工具箱中显示数据网格

推荐文章

如何使用jQuery在屏幕上设置值而不是使用alert?

如何使用jQuery在屏幕上设置值而不是使用alert?

推荐文章

大型IO操作服务器选择哪种技术

大型IO操作服务器选择哪种技术

推荐文章

获取字符串的前n个字符

获取字符串的前n个字符

推荐文章

在Mac OS X中生成鼠标事件

在Mac OS X中生成鼠标事件

推荐文章

可以部署但不能调试.NETCF 3.5应用程序到设备

可以部署但不能调试.NETCF 3.5应用程序到设备

推荐文章

我做错什么了?Python对象实例化是否保留以前实例化的数据?

我做错什么了?Python对象实例化是否保留以前实例化的数据?

推荐文章

C++中多UIS QT应用程序的最佳实践

C++中多UIS QT应用程序的最佳实践