Hello,

I have a form to send pictures, but when I want to display picture it
doesn't work:

class PhotosForm extends Form
{
        public function configure()
        {
                $this->setDataClass('Nt\\SocialBundle\\Entity\\Photos');
                $this->add('nom');
                $this->add(new FileField('filename',
                        array(
                        'secret' => md5("file"),
                        'tmp_dir' => 'bundles/ntsocial/images'
                        )));
        }

My controller to show pictures:

public function showPhotosAction($name)
    {
        $em = $this->get('doctrine.orm.entity_manager');
        $user = $this->findUserBy('username', $name);

        $dql = "SELECT u FROM Nt\SocialBundle\Entity\Photos u".
                        " WHERE u.photosU = ?1";

        $query = $em->createQuery($dql);
        $query->setParameter(1, $user->getId());

        $return = $query->getResult();

        return array('photos' => $return);
    }

And the view:
{% block content %}
        {% for photo in photos %}
                <div>
                        <p>{{ photo.nom }}</p>
                        <img alt="{{ photo.nom }}" src="{{ photo.filename }}">
                </div>
        {% endfor %}
{% endblock %}

The html:
<div>
<p>test</p>
<img alt="gtgt" src="C:\sf9\web\bundles\ntsocial\images
\ec977c68cd42e9fc011dfcdb39abfa85">
</div>

and controller to add a picture:

public function addPhotoAction($name)
    {
        $em = $this->get('doctrine.orm.entity_manager');
        $user = $this->findUserBy('username', $name);

        $photo = new Photos();

        $request = $this->get('request');
        $form = PhotosForm::create($this->get('form.context'),
'Photos');

        $form->setData($photo);

        if ($request->getMethod() == 'POST') {
            $form->bind($request);
            $photo->setPhotosU($user);

            if ($form->isValid()) {
                $em->persist($photo);
                $em->flush();

                return $this-
>render('NtSocial:Social:addPhoto.html.twig', array('form' => $form));
            }
        }

        return $this->render('NtSocial:Social:addPhoto.html.twig',
array('form' => $form));
}

Thank you !

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to