tags:

views:

395

answers:

2

Post hasMany Tag: My form:

$form->input('Post.title');
...
$form->input('Tag.0.name'); //1st tag
$form->input('Tag.1.name'); //2nd tag

This works perfectly, but...

I create some fields Tag.n.name, and I want add each time one tag by $this->data['Tag'][some_number]['name'] = 'all';
Do not ask me why i want that, but tell me how i can add 'all' tag in my model to each Post?

This should get effect 4 INSERT sqls: one add post, and three: 1st tag, 2nd tag, all tag.

More explain: How add more tags without form fields? How add default tags? No input hidden, only pro solutions:)

+1  A: 
$this->data['Tag'][] = array('name' => 'all');

Put this either in your Controller before saving $this->data or in the Model's beforeSave() callback.

deceze
A: 

Thanks for reply...

In Controller this works, I want use this in beforeSave, but this not work, why?

kicaj
1. What exactly doesn't work, any errors? 2. Post your code. 3. Read the manual entry: http://book.cakephp.org/view/683/beforeSave 4. Please reply as a comment or edit your question, don't reply in a new answer.
deceze
beforeSave is a filter for one model only, if you are trying to save tags within the Post-model then you are either doing something wrong or should have a very good reason to do so. Try to refactor your code to do it like deceze said.
Caffeine