We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How to prevent Controller from sending view

I'm communicating with my controller via AJAX and requesting an action. But depending to the result on the said controller, I want it to return particular values, but by now it return a whole "index" template.

I just want it to return what I say it to return. How can I do that?


// In some view...
$.post('my/action', send, function(res){
    // 'res' variable should be 'true' or 'false', not the whole View html, etc...

edited Sep '14
$response = new Phalcon\Http\Response(),

// Do things here.
$varWithThingsDone = 'Doing things.';

    'response' => $varWithThingsDone

You might want to know that you can also check if the post is from AJAX:


@RompePC perfect, worked like a charm, thanks.