这里有关于此的博客文章:
它有一个插件:
还有一些博客文章解释它:
http://rabaix.net/en/articles/2009/07/13/cross-link-application-with-symfony-part-2
(注意:两者都适用于symfony 1.2,但它们也适用于1.4)
要将前端路由到后端,有三个简单的步骤:
1.将以下两种方法添加到后端配置中
这些方法读取后端路由,并使用它来生成路由.你需要提供它的链接,因为php不知道你如何为其他应用程序配置你的web服务器.
.
// 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;
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
2.您现在可以以这种方式链接到您的应用程序:
$this->redirect($this->getContext()->getConfiguration()->generateFrontendUrl('hello', array('name' => 'Bar')));
Run Code Online (Sandbox Code Playgroud)
由于编写起来有点乏味,你可以创建一个帮手
function link_to_frontend($name, $parameters)
{
return sfProjectConfiguration::getActive()->generateFrontendUrl($name, $parameters);
}
Run Code Online (Sandbox Code Playgroud)
该sfCrossLinkApplicationPlugin做到这一点,这一点,但在简单一点的方式,你将能够使用类似的语法与此:
<?php if($sf_user->isSuperAdmin()):?>
<?php link_to('Edit Blog Post', '@backend.edit_post?id='.$blog->getId()) ?>
<?php endif ?>
Run Code Online (Sandbox Code Playgroud)
它会是这样的:
public function executeActionA(sfWebRequest $request)
{
$this->redirect("http:://host/app/url_to_action");
}
Run Code Online (Sandbox Code Playgroud)
在 Symfony 中,每个应用程序都是独立于其他应用程序的,因此如果您需要调用另一个应用程序的操作,您需要直接请求它。
每个应用程序都由一个主控制器(前端、后端、Web 应用程序)表示,该控制器负责将每个请求传递到相应的操作(以及许多其他内容,例如过滤器等)。
我真的建议你阅读这篇文章,它会更具解释性:Symfony - Inside the Controller Layer
| 归档时间: |
|
| 查看次数: |
2590 次 |
| 最近记录: |