Zend Framework:在索引视图中包括其他控制器

发布于 2024-11-08 18:39:54 字数 836 浏览 2 评论 0原文

我是 Zend FW 的新手。我希望在名为 Feedparsercontroller's indexAction 的控制器中编写一个简单的 feedparser。但我想在我的索引页面上将解析后的提要输出显示为小部件。我如何将输出/变量数据驱动到我的索引视图?

下面是我的解析器。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

好听的两个字的网名 2024-11-15 18:39:54

也许我没有完全理解你的问题。

但是,这里最好的方法似乎是创建一个单独的提要控制器,该控制器单独负责与提要相关的业务逻辑(检索、按摩、设置查看等)。

然后,创建一个包含 javascript 代码的部分来调用 feed 控制器,然后输出您想要的小部件。这在一些事情上做得很好。

  1. 它集中了与提要相关的逻辑
  2. 它允许您将提要小部件放置在任何您想要的地方
  3. 这是一种 SOA 方法,通常是一件好事

希望这会有所帮助!

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!

天赋异禀 2024-11-15 18:39:54

我认为小部件的最佳逻辑是ajax

使用一些 js widgets 库(例如 jQuery ui),然后通过一些 ajax 查询加载这些小部件,返回 HTML,这允许您重新加载简单的小部件行为(无需重新加载整个页面) 。

在服务器端,您需要允许通过 ajax 请求调用控制器/操作,并仅发送 html 片段(而不是包含所有布局的整个页面)。

为此,请检查 ContextSwitch 和 AjaxContext 操作助手。您将告诉 FeedparserController 可以使用 XMLHHTTPRequest 中的 /format/html 调用索引操作,在这种情况下,视图助手将是索引。

在 init 部分,您会说可以在 ajax 模式下调用 indexAction,呈现 html 片段 ('html'):

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

现在只需将视图脚本 feedparser/index.phtml 重命名为 feedparser/index .ajax.phtml

在indexAction中,做你的事情并在视图脚本上输出你想要的内容,不要考虑布局组合问题,你正在单独处理你自己的布局部分,并且组合是在js 端。

在 javascript 部分,确保您通过 ajax ($.load 或 $.ajax 与 jQuery 可能)调用带有 format/html 作为参数添加的 url(因此 http://example.com/feedparser/index/format/html)

请注意,在我看来,您应该使用 json 响应而不是 html,也许 json 带有一些里面的html。但这是一个关于如何控制 ajax 通信(以及处理错误、重定向等,这是另一个主题)的问题。

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).

软糯酥胸 2024-11-15 18:39:54

视图助手怎么样?

您可以阅读查看 Zend Framework 中的助手

What about a view helper ?

You can read about it View Helpers in Zend Framework

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文