phalcon - Phalconphp binding view with ajax using volt template -
I am using the Falcon framework, I have a 'controller' post like 'action':
View / Layout / Post.Vault
{% for post in the post}
& lt; H1 & gt; {{Post.content}} & lt; & Frasl; H1 & gt;
& lt; H2 & gt; {{Post.like}} & lt; & Frasl; H2 & gt;
& lt; A href = "#" onclick = "like ();" Data-id = "{{post.id}}" & gt; Such as & lt; & Frasl; A & gt;
{% endfor%}
& lt ;! - - & gt;
& lt; Script & gt;
var such = function () {var id = / * ... * /; // Post ID which is $ Event like '$' Ajax ({Data Type: 'Jason', URL: 'Post / Like /' ID} enhances) (function () {/ * some meaningful});
& lt; & Frasl; Script & gt;
Controller / PostController.PP
/ * ... * /
Public Function Index () {
$ this-> View- & gt; Posts = / * ... * /; // read from the database to show the view
}
public functions such as action ($ id) {
// change 'Like' related post with 'some' id 'foreach ($ this-> view- & gt; post as posted)) {if ($ post-> id == $ id) $ Post- & gt; Like + = 1; / * ... * /} // in the database, and re-submit the entire post view to $ $-> this-> View- & gt; Posts = / * ... * /; // I just allocate 'visual' and hope it works :( $ result = array ('msg' = & gt; 'success'); $ response = new response (); $ response -; gt; setJsonContent ($ result);
}
/ * ... * /
But on button After clicking, nothing has changed! Did I have anything wrong? Can someone help me ... Thanks in advance!
P / S: Sorry for my bad English ... ^^
'$ this-> view-> post' is set to 'index action' only. When this is 'action' it is empty.
Comments
Post a Comment