它不是override single route in symfony2的副本。请耐心等待,仔细阅读我的问题。
我的问题与上述问题不同。 所以,我的Symfony应用程序有一个标准的结构。但它以特定方式配置。
app / config / routing.yml包含多个捆绑路由,例如:
_project_custom1:
resource: "@ProjectCustom1Bundle/Resources/config/routing.yml"
prefix: /custom1
_project_custom2:
resource: "@ProjectCustom2Bundle/Resources/config/routing.yml"
prefix: /custom2
src / 目录有两个捆绑包和下一个结构,例如
Common/AdminBundle/Resources/config/routing.yml
Common/AdminBundle/Resources/config/routing_dashboard.yml
routing.yml
包含下一行:
admin_dashboard_content:
resource: "@CommonAdminBundle/Resources/config/routing_dashboard.yml"
prefix: /dashboard
routing_dashboard.yml
包含:
admin_dashboard_license_content:
path: /license-content
defaults: { _controller: CommonAdminBundle:Dashboard:licenseContent }
下一个捆绑包是自定义捆绑包。如何扩展DashboardController
,覆盖licenseContentAction
并仅覆盖一条(/license-content
)路由并使Symfony使用我的自定义捆绑配置?
复制相同的结构无效。 根据我的解释,我写了这样的话:
<?php
namespace Custom\Custom1\Controller;
use Common\AdminBundle\Controller\DashboardController as BaseController;
class DashboardController extends BaseController
{
public function licenseContentAction()
{
//return parent::licenseContentAction();
die("HELLO!");
}
}
如何为make扩展方法构建路由文件?
答案 0 :(得分:0)
您需要做的就是将这些行添加到public class Notificaciones
{
private WSPradera.ServicioSoapClient WPredial = new WSPradera.ServicioSoapClient();
private WSApartado.ServicioSoapClient WPredialApartado = new WSApartado.ServicioSoapClient();
private WSCopacabana.ServicioSoapClient WPredialCopacabana = new WSCopacabana.ServicioSoapClient();
private WSSanPedroMilagros.ServicioSoapClient WPredialSanPedroMilagros = new WSSanPedroMilagros.ServicioSoapClient();
public Notificaciones(PropiedadesPSE obj)
{
this.objPropiedades = obj;
}
#region Apartadó
public bool Apartado()
{
bool flag = true;
try
{
if (this.objPropiedades.TransactionStatus != "A")
{
return flag;
}
XElement xml = new XElement("referencia", this.objPropiedades.Numfactura);
XElement notificarPago = this.WPredialApartado.GetNotificarPago(xml);
XmlSerializer serializer = new XmlSerializer(typeof(cliente));
StringReader textReader = new StringReader(notificarPago.ToString());
cliente cliente = (cliente)serializer.Deserialize(textReader);
if (cliente.ToString() != "")
{
flag = true;
}
}
catch (Exception exception)
{
this.LogException(Regex.Replace(string.Concat(new object[] { exception.Message, " ", exception.InnerException, " ", exception.StackTrace }), @"\t|\n|\r", "").Replace("'", ""));
throw exception;
}
return flag;
}
#endregion
#region Copacabana
public bool Copacabana()
{
bool flag = true;
try
{
if (this.objPropiedades.TransactionStatus != "A")
{
return flag;
}
XElement xml = new XElement("referencia", this.objPropiedades.Numfactura);
XElement notificarPago = this.WPredialCopacabana.GetNotificarPago(xml);
XmlSerializer serializer = new XmlSerializer(typeof(cliente));
StringReader textReader = new StringReader(notificarPago.ToString());
cliente cliente = (cliente)serializer.Deserialize(textReader);
if (cliente.ToString() != "")
{
flag = true;
}
}
catch (Exception exception)
{
this.LogException(Regex.Replace(string.Concat(new object[] { exception.Message, " ", exception.InnerException, " ", exception.StackTrace }), @"\t|\n|\r", "").Replace("'", ""));
throw exception;
}
return flag;
}
}
文件中。
app/config/routing.yml
使用admin_dashboard_license_content:
path: /dashboard/license-content
defaults: { _controller: CustomBundle:Dashboard:licenseContent }
方法创建一个DashboardController
扩展基本Symfony控制器到licenseContentAction
命名空间。
现在魔术......
如果要保留路径,则必须在CustomBundle
文件的开头添加这些行。路线的名称必须不同(唯一),当然路径必须与覆盖路径相同。
Symfony查找路径,并在匹配时立即将请求重定向到相应的控制器操作。
如果要更改路径,请在routing.yml
文件的末尾添加这些行。路线的名称必须相同。我不确定先前定义的路径(路径)是否仍然存在,我想是的,如果使用此路径进行的请求仍在处理中......
Symfony将路由收集到一个数组中,其中键是路径的名称。通过在文件末尾添加具有相同名称的路由,先前定义的路由将被覆盖。