Thursday, 15 September 2011

Symfony 1.4 jQuery doesn't know user is logged in because of cache? -



Symfony 1.4 jQuery doesn't know user is logged in because of cache? -

i have issue image comments trough jquery. figured out action cached and, when jquery calls action, because of cache, doesn't know sfgaurd user authenticated , hence can't insert comment without user_id (relation problem)

so here how done :

routing :

commentimage: url: /commentimage/:image_id.:sf_format class: sfdoctrineroute options: { model: imagecomments, type: object } param: { module: profile, action: commentimage, sf_format: html } requirements: id: \d+ sf_method: [get, post] sf_format: (?:html|js)

action :

public function executecommentimage(sfwebrequest $request) { $imgid = $request->getparameter('image_id'); $commentpost = $request->getparameter('comment'); $user_id = $this->getcontext()->getuser()->getattribute('user_id','','sfguardsecurityuser'); $comment = new imagecomments(); $comment->setcomment($commentpost); $comment->setimageid($imgid); $comment->setprofileid($user_id); $comment->setfirmbrandid(1); $comment->setpublished(1); $comment->save(); $this->setlayout(false); }

template/form :

<form name="form" id="form<?php echo $photo->getid();?>" method="post"> <input type="hidden" id="image_id" name="image_id" value="<?php echo $photo->getid();?>" /> <input type="text" id="comment" name="comment" value="" /> <button name="submit" class="submit botunlink">komentiraj</button> </form>

and jquery:

$(".submit").click(function(e){ e.preventdefault(); var parent = $(this).parent(); var imageid = get_numbers(parent.attr('id')); var theexactform = "#form"+imageid; $(theexactform).submit(function() { alert($(this).serialize()); homecoming false; }); $.ajax({ data: $(theexactform).serialize(), url: 'http://partytime.hr/commentimage/'+imageid, type: "post", success: function () { $("#allcomments"+imageid).html(""); $("#allcomments"+imageid).load("http://partytime.hr/showimagecomments/"+imageid); //alert('imageid||'+imageid+'forma||'+theexactform+'comment:'+data); }, complete: function() { //$(".allcomments").mcustomscrollbar(); } }); homecoming false; });

when logged in , symfony cache cleared works, later on won't work, because can't update profile_id because cache said wasn't logged in (that's conclusion).

how can prepare this?

jquery symfony-1.4 sfguard

No comments:

Post a Comment