【问题标题】:Symfony Multiple application interactionSymfony 多应用交互
【发布时间】:2011-06-16 06:43:47
【问题描述】:

在symfony 1.4中,如何从当前动作中调用另一个应用程序的动作?

【问题讨论】:

    标签: symfony-1.4


    【解决方案1】:

    这里有一篇关于此的博文

    有一个插件

    还有一些博文对此进行了解释:

    要将前端路由到后端,只需三个简单的步骤:

    1.将以下两种方法添加到您的后端配置中

    这些方法读取后端路由,并使用它来生成路由。您需要提供指向它的链接,因为 php 不知道您如何为其他应用程序配置网络服务器。

    .

    // apps/backend/config/backendConfiguration.class.php
    class backendConfiguration extends sfApplicationConfiguration
    {
      protected $frontendRouting = null;
     
      public function generateFrontendUrl($name, $parameters = array())
      {
        return 'http://frontend.example.com'.$this->getFrontendRouting()->generate($name, $parameters);
      }
     
      public function getFrontendRouting()
      {
        if (!$this->frontendRouting)
        {
          $this->frontendRouting = new sfPatternRouting(new sfEventDispatcher());
     
          $config = new sfRoutingConfigHandler();
          $routes = $config->evaluate(array(sfConfig::get('sf_apps_dir').'/frontend/config/routing.yml'));
     
          $this->frontendRouting->setRoutes($routes);
        }
     
        return $this->frontendRouting;
      }
     
      // ...
    }
    

    2。您现在可以通过以下方式链接到您的应用程序:

    $this->redirect($this->getContext()->getConfiguration()->generateFrontendUrl('hello', array('name' => 'Bar')));
    

    3.由于写起来有点繁琐,可以创建一个helper

    function link_to_frontend($name, $parameters)
    {
      return sfProjectConfiguration::getActive()->generateFrontendUrl($name, $parameters);
    }
    

    sfCrossLinkApplicationPlugin 执行 this,this,但以更简单的方式,您可以使用类似于以下的语法:

    <?php if($sf_user->isSuperAdmin()):?>
        <?php link_to('Edit Blog Post', '@backend.edit_post?id='.$blog->getId()) ?>
    <?php endif ?>
    

    【讨论】:

      【解决方案2】:

      应该是这样的:

      public function executeActionA(sfWebRequest $request)
      {
        $this->redirect("http:://host/app/url_to_action");
      }
      

      在 Symfony 中,每个应用程序都独立于其他应用程序,因此如果您需要调用另一个应用程序的操作,则需要直接请求它。

      每个应用程序都由一个主控制器(前端、后端、webapp)表示,该控制器负责将每个请求传递到相应的操作(以及许多其他东西,如过滤器等)。

      我真的建议你阅读这篇文章,它会更容易解释:Symfony - Inside the Controller Layer

      【讨论】:

      • 完全同意,我没有说它是最好的,但它是一种方式,你看看你发布的artibles,你会发现他们仍然使用文本连接生成一个绝对网址。
      • 当然,最终路由系统就是这样做的:)
      猜你喜欢
      • 2013-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-27
      • 1970-01-01
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多