Dear all,
I have the following stuff to let the user "bookmark a page" or "delete the bookmark" to a news page( in notescontroller).
Codes in NotesController… the bookmark url is something like this:
http://www.123.com/notes/save/420
public function actionSave($id)
{
$assign=NotesUserAssignment::model()->findByAttributes(array('notes_id'=>$this->loadModel($id)->id,'user_id'=>Yii::app()->user->id));
if(!$assign){
$model=new NotesUserAssignment;
$notes=$this->loadModel($id);
$model->notes_id = $notes->id;
$model->user_id=Yii::app()->user->id;
if($model->save())
{
Yii::app()->user->setFlash('notes', "You have successfully bookmarked this notes.");
$this->redirect(array('view','id'=>$notes->id));
}
}
else {
throw new CHttpException(400,'Invalid request. You have already bookmarked this note. Please do not repeat this request again.');
}
}
For the view:
$this->widget('bootstrap.widgets.BootButton', array(
'label'=>'Bookmark it',
'icon'=>'inbox white',
'url'=>'save/'.$model->id,
'type'=>'primary',
'htmlOptions'=>array('data-placement'=>'left','data-title'=>'Bookmark this note', 'data-content'=>'Once you bookmarked the note to your bookmarks, you can access it directly from your profile page.', 'rel'=>'popover'),
));
Is there a way I can do ajaxlink for this…?
I tried
echo CHtml::ajaxLink(
"Link Text",
Yii::app()->createUrl('save/'.$model->id),
array( // ajaxOptions
'beforeSend' => "function( request )
{
//what should i put here....
}",
'success' => "function( data )
{
//...what should i put here
}",
// 'data' => array( 'something here?' ) and this..?
),
array( //htmlOptions
'href' => Yii::app()->createUrl('save/'.$model->id ),
'class' => $someclass,
)
);
I am not very familiar with Yii’s ajax stuff…
Thanks so much for your help!!!!!!!
Thanks again!