Newbie ajax confusion while ostensibly following Cookbook....

You need to load the model in the Ajax request. No doubt the missing $id would be the cause for the error message you get.

Check if you have a get or post call from ajaxlink (get I think). Try something like this (assumes you have $id available in the view)




<?php

echo CHtml::ajaxLink(

    "Another Comment", 

    Controller::createUrl('album/UpdateAjax'), 

    array('update' => '#data', 'data' => $id)

  );

?>



Edit: probably more like this




'data' = '{id:"'.$id.'"}'



(not tested)

/Tommy

Tommy - thanks so much for your help - I finally got it to work!

Not exactly what you wrote, but once got clued in to the need for the id (somehow I thought that was always available as the PK of the record in AR) i was able to figure it out…

<?php echo CHtml::ajaxLink(“Another Comment”, array(‘album/UpdateAjax’, ‘id’=>$model->id), array(‘replace’ => ‘#data’));

I come into this having worked with php for years, but doing just some OOP (mostly database libraries and sanitizing input) and am an MVC / frameworks / Yii virgin… I am really enjoying this but it takes a bit to get my 60 year-old head around this all at once!!

Now I think i will try to abstract actionUpdateAjax a bit further so I can feed it other variables.

michael