0
Hi, I have a news page that the user can like and share the news. Each news has its specific image. In some news, there’s a photo album. When there is the album for the news, the facebook share picks up an album image and not the news image.
I searched around and I thought I should use the meta tag og:image, but only that I’m not able to do it, look at my code
the image is inserted in the news table. in action:
$this->imagem = Doctrine_core::getTable('tbnews')
->createQuery('im')
->select('im.id, im.imagem')
->where("im.imagem != ''")
->andWhere('im.id = ', $request->getParameter('id'))
->limit(1)
->execute();
$response = $this->getResponse();
$response->addMeta("og:image", "http://www.meusite.gov.br/upload/noticias/<?php echo $this->imagem;");
and that’s what I get in return in page rendering:
<meta content="http://www.meusite.gov.br/upload/noticias/<?php echo <pre> Doctrine_Collection data : Array( 0 : Object(tbNews) ) </pre>; ?>" name="og:image">
i got this answer: Fatal error: Call to Undefined method Doctrine_collection::getImagem(). And this is what appears in the html: <meta content="http://www.meusite.gov.br/upload/noticias/" name="og:image">
– Estácio Di Fabio
Your query returns a collection of entities, not just a single entity. You need to take the first object from resultset and then print the ebject attribute you want on the meta tag.
– Rodrigo Rigotti
yes it is, but it’s not happening. um.
– Estácio Di Fabio
Try to access the first Collection object with:
$this->imagem[0]->getAtributo()
– Rodrigo Rigotti
that’s how you print an image of the bank on the screen, but not the right image, take any one and play the same image for all pages :T
– Estácio Di Fabio
but anyway og:image is not picking up the image that appeared in the meta tag.
– Estácio Di Fabio
What meta tag is being generated?
– Rodrigo Rigotti
Let’s go continue this discussion in chat.
– Estácio Di Fabio