Kohana 3.1:从另一个控制器中调用另一个控制器;不返回数据

发布于 2024-11-02 05:23:09 字数 703 浏览 3 评论 0原文

我似乎无法解决这个问题...我有几个问题,请耐心等待! :)

首先,设置:
我有一个扩展 Controller_Template 的控制器(controllerA)。在controllerA 的模板视图中,我有jQuery 选项卡,它可以AJAX 加载另一个控制器(controllerB)。然后我有一个“核心”控制器,其中包含我在其他控制器中重用的功能(好吧,无论如何我都愿意)。

现在我的问题是:

1. 像我上面提到的那样加载 jQuery 选项卡内容是否可以(最佳实践):

  • 测试
  • 2. 在 JS 和 PHP 中,我一直有一个用于可重用代码的“核心”文件。有没有更好的替代方法?我应该让我的核心扩展控制器,然后扩展我的所有控制器吗?但我担心开销。

    3. 最后,如果我使用 Request::factory()->execute()->response() 调用核心,除非使用像 die($data) 而不是 return $data 它。但是,如果我从核心中的另一个函数调用该函数,它将无法工作。我怎样才能让它全面发挥作用?

    感谢您一如既往的帮助!

    布莱恩

    I just can't seem to get my head wrapped around this... I have a few questions, please bear with me! :)

    First, the setup:
    I have a controller (controllerA) which extends Controller_Template. Inside controllerA's template view I have jQuery tabs which AJAX-loads another controller (controllerB). And then I have a "core" controller which contains functions that I reuse within other controllers (well, I would LIKE TO anyway).

    Now for my questions:

    1. Is it okay (best practice) to be loading the jQuery tab contents like I mentioned above, with:
    <li><a href="/controller">test</a></li>?

    2. In JS and PHP I've always had a 'core' file for reusable code. Is there a better alternative to doing it this way? Should I instead have my core extend Controller and then extend all my controllers off of that? I'm concerned about the overhead though.

    3. Last, if I call the core with Request::factory()->execute()->response(), I get nothing back unless I use something like die($data) instead of return $data it. But if I call that function from within another in the core, it won't work. How can I make it work across the board?

    Thanks for your help, as always!

    Brian

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

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

    发布评论

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

    评论(1

    慕烟庭风 2024-11-09 05:23:09
    1. 使用反向路由生成
      项目 URI。或者你将修改所有
      更改路由规则后您的看法。
    2. 在您的中扩展 Controller_Template
      基本控制器类 - 它将是
      所有其他的父类
      控制器。
    3. Request::factory()->execute()->response()
      返回字符串,所以你至少需要
      回声。并且不要忘记设置
      $this->请求->响应
      阿贾克斯方法。
    1. Use reverse routing to generate
      project URIs. Or you will modify all
      of your views after changing in routing rules.
    2. Extend Controller_Template in your
      basic controller class - it will be
      parent class for all other
      controllers.
    3. Request::factory()->execute()->response()
      returns string, so you need at least
      echo. And dont forget to set
      $this->request->response in your
      ajax method.
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文