简体   繁体   中英

CakePHP: Using timthumb with Html helper?

I just started using cakephp for the first time and I don't know how to use timthumb with the html helpers. My code goes like this:

$this->Html->image('timthumb.php?src='.$receta['Receta']['imagen'].'&h=246&w=618', array(
        "alt" => $receta['Receta']['nombre_receta'],
        'url' => array('controller' => 'recetas', 'action' => 'view', 6)
    ));

and it gives me this html:

<a href="/recetas/view/6" ><img alt="Helado de Fresa" src="/img/timthumb.php?src=fresa.png&amp;h=246&amp;w=618"></a>

But that won't make the images show up. I have timthumb.php inside /webroot and the images inside /webroot/img . Also I have my cache and temp folders inside /webroot but I don't have a clue if that's ok?

If I remove the timthumb code the image will show (just not at the proper size)

You have to specify that timthumb.php is in the web root, otherwise the image method assumes the timthumb script is in the /img folder. This also means you have to modify the value for the src parameter:

$this->Html->image('/timthumb.php?src=/img/'...

For the cache and tempory files I would use CakePHP's /app/tmp resp. /app/tmp/cache folders.

An old question, but you can also use TimthumbPlugin for CakePHP. It wraps the timthumb library and provides an easy to use helper for that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM