Php – Set default data in a selection box in HABTM model

cakephpPHP

My system allows users to add events, which include date, time, and places. On the other hand, users are allowed to choose the "Event sharing to" other users. I successfully create events and share them among users. When the user logs in to see which users are being chosen to share with an event, he is able to get a view for that particular event.

But the problem is, when a user adds the event, he must choose his own name as well in the select box. If he does not, he will be unable to read the event that he himself had created. So I need to save some default data to my model which whenever the user chooses to share an event or not, it also will save the same data to his user ID.

What can I edit to let it set a default saving value which is always saved with the user's own data? Here is my code for select box:

input('User',array( 'label' => 'Select Related
Potential', 'options' => $users,
//'id'=>'user',
'style'=>'width:250px;height:100px',
//'selected' => $ownUserId )); ?>

I tried to solve this by adding 1 more row to the add.ctp. But the permission was just set to the user who created it. The other chosen user were unable to read it.

$form->input('User',array(
'label' => 'Select Related Potential',
'options' => $users, //'id'=>'user',
'style'=>'width:250px;height:100px',
'selected' => $ownUserId ));

$form->input('User',array('type'=>'hidden','value'=>$ownUserId));

Best Answer

Its been a while, but I think you should tweak the save function in the model to do that instead of putting it in the view like you are trying.

Related Topic