Phalcon Cheatsheet

echo Phalcon\Version::get(); get phalcon version

Routes

  • Retrieve route parameter $id = $this->dispatcher->getParam("id");
  • Retrieve GET request $id = $this->request->get('id');
  • Retrieve POST request $id = $this->request->getPost('id');
  • Volt

    $this->view->setTemplateBefore('public'); $this->view->disable(); $this->view->pick("item/close_window"); $this->view->title = "Title"; $this->view->setVar("title","Title");

Templates

{{ post.title }}
  • Get url

    {{ router.getRewriteUri() }}

Redirects

return $this->response->redirect($this->request->getHTTPReferer());
return $this->response->redirect("contact/index");
  • redirect to another controller action

    $this->dispatcher->forward(['action' => 'index']);

Flash Messages

Setting

$this->flash->error("too bad! the form had errors");
$this->flash->success("yes!, everything went very smoothly");
$this->flash->notice("this a very important information");
$this->flash->warning("best check yo self, you're not looking too good.");
$this->flash->message("debug", "this is debug message, you don't say");

View

$this->flashSession()->getMessages();

Rendering in volt

{{ this.flashSession.output() }}

Overriding Flash classes

use Phalcon\Flash\Direct as FlashDirect;

// Register the flash service with custom CSS classes
$di->set(
        "flash",
        function () {
                $flash = new FlashDirect(
                        [
                                "error"   => "alert alert-danger",
                                "success" => "alert alert-success",
                                "notice"  => "alert alert-info",
                                "warning" => "alert alert-warning",
                        ]
                );

                return $flash;
        }
);