CakePHP save without form

I have a photo gallery I'm trying to set a picture as the cover for the album. I have a field cover_id in the albums table that has already been linked to the photos through the model. I'm passing the album_id and photo_id to the controller. I want to update the album.cover_id passed thru the params with the photo_id passed thru the params. Is there a way to do this or a way to make the link a form without having it look like or form or changing much of the CSS?

Saving data and forms are two separate things, you can use one without the other. You can pass variables from the browser to the server either via POST (usually a form) or GET (in the URL). Mix and match that to do whatever you want to do. For example:

echo $html->link('Set as cover', array('controller' => 'albums', 'action' => 'set_cover', 42, 123));

URL:/albums/set_cover/42/123

class AlbumsController extends AppController {

    function set_cover($album_id, $photo_id) {
        $this->Album->save(array('id' => $album_id, 'cover_id' => $photo_id));
    }

}

I would just add it to the data array prior to saving

$this->data['Album']['cover_id'] = $this->params[0];
$this->data['Album']['id'] = $this->params[1];

$this->Album->save($this->data);

If you want to have a look, you can alwayspr()$this->paramsto see what the controller is aware of.

Tags: cakephp
What Others Are Reading