Sorry guys I just cannot figure this one out. I creating an ajax
comment system that does not have to reload all of the comments (i.e.
foreach loop getting all of the comments) So what I have done is
create a dummy <div> that the comment will be loaded into, and when
the page is reloaded, it will automatically be placed with the other
comments as usual. The problem is, in my ajax function, it won't
search, find, or in any way see $this->Comment->id or $this->Comment-
>getLastInsertId() for anything after the save.And I do have the debug
level set to 2, and it seems like a query is never being run, except
for where i will explain below The controller looks like so...
function viewstuff(){
$this->layout = 'ajax';
if($this->Comment->save($this->data){
/*Here is everything i have tried, corresponding with their sql
queries it runs */
// $this->set('comment' ,$this->Comment->findById($this->Comment-
>getLastInsertId()));
//SELECT `Comment`.`id`, `Comment`.`body`, `Comment`.`user_id`,
`Comment`.`story_id` FROM `comments` AS `Comment` WHERE `Comment`.`id`
IS NULL LIMIT 1, now I have no idea why it sets the id to IS NULL, my
guess is that this means the ID has not been set yet, but i don't
understand this because I have only called upon this function unless I
have saved, meaning the id SHOULD be set
//here is everything i have tried, that does not work
//$id = $this->Comment->id ;
// $this->set('comment', $this->Comment->read($id));
//returns a sql query that is blank
$tmp_id = $this->Comment->id;
$this->set('comment', $this->Comment->findAll("id = $tmp_id"));
//this returns a sql error...
//it queries like this, not querying for the id SELECT `Comment`.`id`,
`Comment`.`body`, `Comment`.`user_id`, `Comment`.`story_id` FROM
`comments` AS `Comment` WHERE id =
//then returns the error
//you have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '' at line 1
***I have tried these and many more, and am begging for assistance :P
Here is my corresponding view as well,
<?php pr($comment); ?>
//this is all it is because i am just testing right now
**And I should add I am using jquery to call upon this function (and
the data is saved successfully btw)
<script type="text/javascript">
// wait for the DOM to be loaded
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#myform').ajaxForm(function() {
$("#newcomment").load('/stories/viewstuff');
// $("#newcomment").load('/stories/lastcomment');
});
});
</script>
And just a side note as well, I can set ANY VARIABLE in the controller
above that I am attempting to call the $this-.Comment->Id or $this-
>Comment->getLastInsertId(); and it will UPDATE JUST FINE. THIS IS
ONLY A PROBLEM WITH $THIS->COMMENT->ID or $THIS->COMMENT-
>GETLASTINSERTID() NOT BEING SET.
Everything else, all variables, queries, etc. in the controller are
set just fine. I am wondering if for some reason the getLastInsertId
or id is not being set right away for some reason?
Any advice is GREATLY appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---