davidyell / CakePHP-Proffer

An upload plugin for CakePHP 3
MIT License
117 stars 63 forks source link

How do I get the uploaded image to display? #253

Closed coyatsi closed 6 years ago

coyatsi commented 6 years ago

I am still new on matters cakePHP. I have managed to successfully upload files but I cannot display them. From the manual: $this->Html->image('../files/<table>/<field>/' . $data->get('image_dir') . '/<prefix>_' . $data->get('image')); Am I supposed to replace the table and field with the actual names? What is $data? See my code below (baked), kindly point out any issues.

Controller

public function view($id = null)
    {
        $organiser = $this->Organisers->get($id, [
            'contain' => ['Events']
        ]);

        $this->set('organiser', $organiser);
        $this->set('_serialize', ['organiser']);
    }

view.ctp

<?= $this->Form->create($organiser, ['type' => 'file']) ?>
        <?= $this->Form->input('name', array('label' => 'Organiser name')); ?>
        <?= $this->Form->input('about', array('label' => 'About','type' => 'textarea')); ?>
        <?= $this->Form->input('email', array('label' => 'Email', 'type' => 'email')); ?>
        <?= $this->Form->input('phone', array('label' => 'Phone')); ?>
        <?= $this->Html->image('../files/organisers/photo/' . $organiser->get('photo_dir') . '/<prefix>_' . $organiser->get('photo')); ?>
    <?= $this->Form->end() ?>
davidyell commented 6 years ago

The <prefix> is supposed to be replaced with your thumbnail prefix. So if you configure your thumbnail with small in the behaviour configuration, then that will be /small_.

If you look in your /webroot/files folders, you should be able to see the files with their prefixed names.

What is $data? That's the entity you pass to your form, so in your case $organiser.

coyatsi commented 6 years ago

Thank you!