Zend Framework headMeta () - keywords are not added

I am using Zend Framework 1.8. I have a problem with headMeta () duplicating my meta keywords.

In my layout.phtml, I have <?php echo $this->headMeta(); ?> <?php echo $this->headMeta(); ?>

I have a custom Controller_Plugin_ViewSetup (extending Zend_Controller_Plugin_Abstract ) that has the following code in it in the dispatchLoopStartup() function:
$view->headMeta()->setHttpEquiv('Content-Type', 'text/html;charset=utf-8'); $view->headMeta()->setName('keywords', 'global,generic,keywords,');

Finally, in my view scripts, I have the following:
$this->headMeta()->appendName('keywords', 'view,specific,keywords');

I expected in my HTML source code I would see:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="keywords" content="global,generic,keywords,view,specific,keywords" />

However, I really see this:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="keywords" content="global,generic,keywords," />
<meta name="keywords" content="view,specific,keywords" />

In other words, meta keywords are not combined together as they should. What am I doing wrong?

Cheers
Matt

+4
source share
1 answer

This is because the append method does not add more keywords to an already defined list. The append method will add the following tag to already defined tags. Similarly, if you selected prepend, this will add your new tag to the one you defined in your plugin.

I think the best thing would be to remove the keyword holder from the plugin and save the default keywords in your configuration object and paste them into your view at the same time that you add additional keywords.

+5
source

Source: https://habr.com/ru/post/1286415/


All Articles