开发者

CakePHP - how to inlclude a form field not associated with the model

开发者 https://www.devze.com 2023-03-29 00:04 出处:网络
Assuming I have a view in CakePHP which uses the Form Helper to create the form fields like so: ec开发者_如何转开发ho $this->Form->create();

Assuming I have a view in CakePHP which uses the Form Helper to create the form fields like so:

ec开发者_如何转开发ho $this->Form->create();
echo $this->Form->input('id');
echo $this->Form->input('headline');
echo $this->Form->input('paragraph');
echo $this->Form->end(__('Submit', true));

...and assuming once the form is submitted to the controller I then do a save() to update the record...

How would I include another input field in the form that is NOT associated to the model in question and which I want to put in there to capture another piece of data that I intend to process separately in the controller action?

(To give some background: the additional field I want to add is actually an image filename. My images table is a completely separate entity, and because it therefore has no association with the model I'm save()ing, I believe I need to capture the information in an additional field on the form, then process it 'manually' in the controller action - i.e., by importing the images model and creating a new record in it based on the image upload filename I've added to the form.)

Hope that makes sense!

Thanks.


echo $this->Form->input('file_image', array('type'=>'file'));

Then in your controller see what is returned and use that file and upload it to your server.

0

精彩评论

暂无评论...
验证码 换一张
取 消