We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

AJAX routing

how to make a route from Ajax request, that something like: $router->addAJAX("/products/edit/{id}", "Posts::edit"); or how?



98.9k

You can validate if the request is ajax in the action itself:

<?php

class PostsController extends Phalcon\Mvc\Controller 
{

    public function editAction()
    {

        if (!$this->request->isAjax()) {
            $this->flash->error('The request is not ajax');
            return;
        }

        //...
    }
}