• 17th July 2009 - By dan

    I recently had a bit of a brain block how to do a certain thing in cakePHP – I basically wanted to update a model from a view but not using a GET method (as that would have allowed URL manipulation – and potentially created problems).

    The simple answer (again thanks to Darren at zeen.co.uk) is to use a form to submit the data you need.

     
    echo $form->create('SongList');
     
    echo $form->input( 'sttw_track_id', array( 'value' => $track['SttwTrack']['id'], 'type' => 'hidden') );
     
    echo $form->input( 'user_id', array( 'value' => $userID_Logged, 'type' => 'hidden') );
     
    echo $form->submit($this->webroot . 'images/add_to_list.png', array('style' => 'width:31px; height:52px'));
     
    echo $form->end();

    This basically means that rather than creating a GET type URL (/controller/action/param1/param2) – I can now submit information pre-populated using POST. I know this seems obvious now you look at it, but to many newbies in CakePHP – doing something like this when there is so much automagical stuff going on can sometimes be overlooked.

    Share with your friends and help out this site:
    • Digg
    • del.icio.us
    • Facebook
    • Google Bookmarks
    • E-mail this story to a friend!
    • LinkedIn
    • Live
    • Reddit
    • StumbleUpon
    • Twitter
    • Yahoo! Bookmarks

Ad