Symfony Multiple application interaction

倖福魔咒の 提交于 2019-12-03 07:00:39

There's a blog post about that here:

There's a plugin for it:

And there are some blogposts explaining it:

To route to your frontend to your backend, there are three easy steps:

1. Add to your backend configuration the following two methods

These methods read the backend routing, and use it to generate routes. You'll need to supply the link to it, since php does not know how you configured your webserver for the other application.

.

// 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. You can link to your application in such a fashion now:

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

3. Since it's a bit tedious to write, you can create a helper

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

The sfCrossLinkApplicationPlugin does this , this, but in a bit simpler fashion, you would be able to use a syntax similar to this:

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

It would be something like this:

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

In Symfony each application is independent from the others, so if you need to call an action of another app, you need to request it directly.

Each app is represented by one main controller (frontend, backend, webapp), this controller takes care of the delivery of each request to the corresponding action (and lots of other things like filters, etc.).

I really recommend you to read this, it would be quite more explanatory: Symfony - Inside the Controller Layer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!