简体   繁体   English

覆盖CakePHP头/头

[英]Override CakePHP head/header

EDIT: I found the solution, but now there is a problem with cakePhp itself 编辑:我找到了解决方案,但cakePhp本身存在问题

I am using: 我在用:

<?php if (isset($image)) echo $this->Html->meta(array('name' => 'og:image', 'content' => $image)); ?>

and it generates 它产生

<meta name="og:image" content="https://test.com/img/sharer/startseite.jpg"/>

Sadly Facebook doesn´t like the /> at the end (related here Facebook Open Graph Error - Inferred Property ) 可悲的是,Facebook不喜欢结尾处的/>(此处与Facebook Open Graph错误-推断属性有关

I have to use it with a space - but CakePhp generates it that way. 我必须在空格处使用它-但CakePhp会以这种方式生成它。 Any ideas? 有任何想法吗?

In CakePHP 3, you can find templates for the HTML helper in vendor/cakephp/cakephp/src/View/Helper/HtmlHelper.php . 在CakePHP 3中,您可以在vendor/cakephp/cakephp/src/View/Helper/HtmlHelper.php找到HTML帮助器的模板。

Copy those to config/templates/html-templates.php and enhance them according to your demands. 将它们复制到config/templates/html-templates.php并根据您的需求进行增强。

Then, in your \\App\\Controller\\AppController , add 然后,在\\App\\Controller\\AppController ,添加

public $helpers = [
  ...
  'Html' => ['templates' => 'templates/html-templates'],
];

and use your HTML helper as usual. 并照常使用HTML帮助器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM