folks. I'm starting with CakePHP and after reviewing this tutorial ( http://book.cakephp.org/view/1543/Simple-Acl-controlled-Applica开发者_如何学Gotion ) and also after having used the "cake bake" command to generate my models, controllers and views , everything is fine, but when I visit the Post's add view (views \ posts \ add.php), I find that instead of showing a input text for the username, it shows a select with all the usernames.
this is the line in the Post's add view that show the select.
echo $this->Form->input('user_id');
PostsController :
function add() {
// Some other code
$users = $this->Post->User->find('list');
$this->set(compact('users'));
}
Although I know how to display only the username of the currently logged-in user, I don't know how to control the content to show in $this->Form->input() because if I use a variable that is not part of the "Post" model , it's shown , but as the label for the input.
Have you any idea how to solve this??
P.S. I've been trying to find this information on the cookbook , but I haven't been able to find anything specific to my situation :(
If you want to add a string in as the value of the input, try this :
echo $form->input('my label text',array('value'=>'the value string','type'=>'hidden'));
That would make the input hidden, and set the value.
Or remove the type=>hidden
and it will have a value, you can also add things like disabled
and such in there, or to modify the div
it creates, use div'=>array()
and put your div
options in that array... hope this helps.
i would like to help you on this thing.
first of all when you want a text box then you must define the type of the input field.
echo $form->input('user_id', array('type'=>'text', 'label'=false));
i hope this will help you.
精彩评论