og:image with database image - symfony php

Asked

Viewed 66 times

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">

2 answers

0

Exchange the:

$response->addMeta(
    "og:image",
    "http://www.meusite.gov.br/upload/noticias/<?php echo $this->imagem;"
);

... for:

$response->addMeta(
    "og:image",
    "http://www.meusite.gov.br/upload/noticias/" . $this->imagem->getAtributo()
);

In the above example I used a method getAtributo() (which probably does not exist) of the class tbnews to print this attribute on the meta tag. Change the method to another of your choice.

  • 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">

  • 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.

  • yes it is, but it’s not happening. um.

  • Try to access the first Collection object with: $this->imagem[0]->getAtributo()

  • 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

  • but anyway og:image is not picking up the image that appeared in the meta tag.

  • What meta tag is being generated?

Show 3 more comments

0

I found the solution. I had to rewrite the addMeta() function so that the parameter name be replaced by property.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.