Yii Framework Forum: Newbie ajax confusion while ostensibly following Cookbook.... - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Newbie ajax confusion while ostensibly following Cookbook.... Rate Topic: -----

#21 User is online   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,832
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 12 February 2010 - 08:06 PM

View PostMichael Sullivan, on 12 February 2010 - 07:30 PM, said:

OK, loadModel()could be the culprit...

here is the code for loadModel and for actionUpdateAjax. I want to get some data from the AR, and thought I needed to call loadModel() but notice that if the model is null that 'The requested page does not exist.' is thrown

notice that I commented out the loadModel call in actionUpdateAjax -- when I just ran it, I did not get the error. But I STILL didn't get the data I wanted for AR either. So I'm probably not accessing that data properly....


would I need to pass the id variable from the ajaxLink call in view.php along with the data about the controller file?

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)
echo CHtml::ajaxLink(
    "Another Comment", 
    array('update' => '#data', 'data' => $id)

Edit: probably more like this
'data' = '{id:"'.$id.'"}'

(not tested)

This post has been edited by tri: 12 February 2010 - 08:28 PM

Don't forget to read The Definitive Guide to Yii (1.1/2.0 en) | The class reference (1.1/2.0) has the details

#22 User is offline   Michael Sullivan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 06-February 10

Posted 12 February 2010 - 09:40 PM

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.


Share this topic:

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users