An approach

in the controller:

function show_image($recordId) {
    $this->set('data', $this->Model->findById($recordId));
    $this->layout = 'ajax'
}


the view show_image.ctp:

Configure::write('debug', 0);
header("Content-type: image/jpeg"); //assume jpg image
echo $data['Model']['blob_file'];


your view:

echo $html->tag('img', array(
'src' => Router::url(array('controller' => 'your_controller', 'action' => 'show_image', $userInfo['Photo'][0]['id']))
    )
);


Regards

MARTIN



On 05/13/2010 12:26 AM, Ed Propsner wrote:
Besides the size there should be no diff between "binary" and "blob", I was just thinking that perhaps Cake handled them differently. I played around with media view and it doesn't seem to be what I'm looking for.

I have it narrowed down to the headers and I can get the photo to display but it has to be in it's own view and even then I have to echo the image directly in the controller action ... this isn't working for me. I never usually store photos directly to the database but in this instance i feel it better serves my purpose without taking a hit on performance.

Ideally I would like to access the image through it's $hasMany assoc and nest it in an image tag but I'm at a loss for how to pull that off with Cake.



On Wed, May 12, 2010 at 3:12 PM, Ed Propsner <crotchf...@gmail.com <mailto:crotchf...@gmail.com>> wrote:

    I've been toying with this one for a while now and I'm not really
    getting anywhere.

    I'm trying to display a photo stored in db as type "blob". With
    conventional PHP I would normally store the photo with type
    "binary" and never had any issues ... Blob is not going so well.
    I figure the problem has something to do with content type but MVC
    is confusing me a bit when it comes to headers or media views. It
    seems straightforward enough but I think I'm going about the wrong
    way (I'm not using media view or headers at this point).

    In my Users Model I set up a $hasMany assoc.

     var $hasMany = array(
            'Photo' => array(
                'className'     => 'Photo',
                'foreignKey'    => 'user_id',
                'conditions'    => array('Photo.profile' => 1,
    'Photo.private' => 0),
                'limit'        => '1',
                'dependent'=> true
            )
        );

    Rendering the photo is the problem.

    > View

    $html->tag('img', array(
                                      'src' =>
    $userInfo['Photo'][0]['file']
                                     )
                    )

    the "file" part of the array is empty:

      [Photo] =>  Array
             (
                 [0] =>  Array
                     (
                         [file] =>
                         [user_id] =>  1
                     )

             )

    I tried a lot of different things but nothing worked the way I
    want. What is the proper way to go about this?

    - Ed


Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to