How to get the full path of an image, saved in mysql in a controller

88 views Asked by At

I have a simple cms in witch you can add an image(for example a Logo) in the database. I dont save the imge itself, just its name(logo.jpg). Now in twig i ussually render the image like this:

src="{{ app.request.scheme ~'://' ~ app.request.httpHost ~ asset(skin.logo.webPath("content")) }}">

This gets the images path and shows the image. It works in twig...

Nut now I need to show the image in the email so I need to use the swiftmailers embed thing.. For that I need to get the images path in the controller... How can I do that? How can I get the full path from the databases?

UPDATE

So this is what I tried so far. I get the logo name and then get his aabsolute path. And add it to the swiftmailer:

$skinLogo = $em->getRepository('MediaparkLtSkinBundle:Skin')->getSkinByHost()->getLogo();
            $logoUrl = $this->getRequest()->getScheme() . '://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBasePath($skinLogo);

            $message = Swift_Message::newInstance();
            $imgUrl = $message->embed(Swift_Image::fromPath($logoUrl));
            $message->setSubject($this->container->get('translator')->trans('successfull.registration'))
                ->setFrom($skinEmail, $this->container->getParameter('customer.care.email.sender'))
                ->setTo('[email protected]')
                ->setBody($this->container->get('templating')->render('MediaparkLtUserBundle:Email:registration.html.twig', array('url'=>$imgUrl)), 'text/html');
            $this->container->get('mailer')->send($message);

And in twig:

src="{{ url }}"

However this is what url I am getting:

?ui=2&ik=44715ce76c&view=fimg&th=14e017a2b3b2962d&attid=0.1&disp=emb&attbid=ANGjdJ-13845qdAQv5agvpIx1hqao8QjaSinWtCRLVNEdGqMT6NUvR3ehiGS54HFfQFjxAyAOFsq11IyDzne7HdqO2b48KvSXEP_SzTsrU4gqsD-i3VeXzjH3tPR0xk&sz=w394-h114&ats=1434543863132&rm=14e017a2b3b2962d&zw&atsh=0

0

There are 0 answers