Setting a Default value in a View:
echo $this->Form->input('form field name here',array('value' => '1234567'));
The newest version of Cakephp makes it even easier to make a JSON or XML request.
Add the request handler component to your controller;
public $components = array('Paginator','RequestHandler' );
create your action in your controller;
eg
public function testjson() { $this->set('posts', $this->paginate()); $this->set('_serialize', array('posts')); }
To access either the JSON or XML version simply append .json or .xml to the action name;
http://localhost/myapp/posts/testjson.json
http://localhost/myapp/posts/testjson.xml
Manual:
If your trying to save the a foreign key of something heres how you can do it. Eg you want to save the user_id to the products table but you dont want the user to be able to input the user id as there all ready logged in;
In the your view add this line;
echo $this->Form->hidden('user_id', array('value' =>AuthComponent::user('id')));
Display Field instead of ID:
Whenever CakePHP automagically fetches lists from your tables, it uses the id key for the value and the $displayField for the text.
If your table has a name or title field, CakePHP automatically displays it as the display field. So, either rename the field that you want as your display field (say, candidate_name to just name) or set the $displayField variable in your model:
class Candidate extends AppModel { var $displayField = 'candidate_name'; }
Source:
http://stackoverflow.com/questions/4558505/cakephp-related-tables-show-ids-instead-of-values
Manual: