Symfony Generaturl问题....必须匹配; (“我的特殊字符”字符串“给出)生成相应的URL。”
我正在尝试将Google索引器API与Symfony一起使用,因此我需要像在前端中已经使用的工作实用性(在数据库中)动态生成相同的URL。
我的控制器函数外观(减少)在我的前端中像这样
/**
*
* @Route({
* "de": "/profile/{name}-{id}/career/{jobname}-{jobid}",
* }, name="somename")
*/
public function detailfunction($name, $id, $jobname, $jobid)
{ // some code
}
我得到以下由twig(路径函数)呈现的URL:
因此,现在我需要将完全相同的URL发送到Google,因此每当修改此页面时,它都会更新索引。
我尝试在这样的“ Google Indexer”函数的控制器中生成此URL:
$job = $this->getDoctrine()->getRepository(Jobs::class)->findBy(....);
$url = $this->generateUrl('somename', array('name' => $job->getCompany()->getName(),
'id' => $job->getCompany()->getid(),
'jobname" => $job->getTitle(),
'jobid' => $job->getId()));
// Debug
echo $url;
不幸的是,它输出“错误:参数“ Jobname” for route“ somename”必须匹配“ [^/] ++”(“ Worker Montage(M M Montage)(M /w/d)“给定)生成相应的URL”,
因此它不会编码来自URL生成器数据库的数据。我一直想知道Symfony(或树枝)实际上是如何在内部编码的,但我完全迷失了方向,非常感谢暗示。
I am trying to use the google indexer api with symfony and therefore i need to generate the same URLs dynamically from my job-entity (in the database) like i am already using in the frontend.
My controller function looks (reduced) like this
/**
*
* @Route({
* "de": "/profile/{name}-{id}/career/{jobname}-{jobid}",
* }, name="somename")
*/
public function detailfunction($name, $id, $jobname, $jobid)
{ // some code
}
In my frontend i get the following url rendered by twig (path function):
https://www.mydomain.xy/profile/This+is+a+company+name-23/career/Worker+Montage+%2528mwd%2529-135
So now i need to send the exact same url to google so it updates the index whenever this page is modified.
I try to generate this url in the controller of my "google indexer" function like this:
$job = $this->getDoctrine()->getRepository(Jobs::class)->findBy(....);
$url = $this->generateUrl('somename', array('name' => $job->getCompany()->getName(),
'id' => $job->getCompany()->getid(),
'jobname" => $job->getTitle(),
'jobid' => $job->getId()));
// Debug
echo $url;
Unfortunately it outputs "ERROR : Parameter "jobname" for route "somename" must match "[^/]++" ("Worker Montage (m/w/d)" given) to generate a corresponding URL"
So it doesn´t encode the data that comes from the database for the url generator. I have been wondering how symfony (or twig as well) actually encodes internally but i am completely lost and very thankful for a hint.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管我仍然不确定Symfony / Twig编码URL的确切方式,但我写了一个小的解决方法,并在将其传递给GenerateUrl函数之前将其调用。
Although i am still not sure of how exactly symfony / twig encodes the url, i wrote a small workaround function and call it before passing it to the generateURL function.