Friday, December 28, 2012

Re: Dealing with Image Uploads

One approach is to add foreign_key and model columns to your images
table so you can create associations between Image and other models
like this:

public $belongsTo = array(
'Publication' => array(
'className' => 'Publication',
'foreignKey' => 'foreign_key',
'conditions' => array(
'Image.model' => 'Publication'
),
'dependent' => true
),
'Author' => array(
'className' => 'Author',
'foreignKey' => 'foreign_key',
'conditions' => array(
'Image.model' => 'Author'
),
'dependent' => true
)
);

You can then store settings for the various models within the Image class:

public $settings = array(
'Publication' => array(
'directory' => 'img/publications',
'width' => 220,
'height' => 288,
'wp' => 220,
'hp' => 288,
'wl' => 220,
'hl' => 288
),
...
);

Then create an ImageComponent to handle the upload and resize,
accessing the required settings much the same way that a behavior
reads its own settings for a given model. That is,
$this->__Controller->{$model}->Image->settings[$model]['width'], or
something similar. Of course, you'll need to pass the desired model
somehow, either in the upload form or as a parameter passed from the
controller to the component.

For Thumbnails, create a separate table and associate them by
image_id. The class itself can also have a $settings array similar to
that in Image, so that you can have various sizes of thumb.

On Fri, Dec 28, 2012 at 12:44 AM, Advantage+ <movepixels@gmail.com> wrote:
> I need to figure out the best way from the backed the admin can upload
> images, the tricky part is the site has all different kinds of images (small
> product thumbs, large version, they want to be able to upload images into
> the jquery slider on the home page, images for a new sections, featured
> product on index page to name a few of the different sizes)
>
>
>
> And there is no way to know if they are even going to upload the right
> dimensions for each type of image.
>
>
>
> What is the best way to do this? I cannot seem to think of anything having a
> table for each_image how it relates to that page, that seems like the
> opposite of what should be done.
>
>
>
> Any idea would be great.
>
>
>
> Thanks, Dave
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com.
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>
>

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.

No comments: