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

Can phalcon auto bind request parameter to controller?

If I create a controller with attribute, can phalcon auto assign value to these attribute?

<?php

class LoginController extends BaseController
{
    $username;
    $password;

    public function indexAction()
    {
        //Don't use this to get parameter
        //$username=$this->request->getPost('username');
        //$password=$this->request->getPost('password');
    }

}

No, it can't. The code that runs in your function cannot have other code injected into it, so there is no way to have $username defined. $this->username could be defined, but I don't think Phalcon does this. In truth, you wouldn't want to do that anyway, because then $username would become a bit of a magic variable - when you (or someone else) is debugging, it wouldn't be obvious from the code where $username gets initialized. Using $this->request->getPost('username') is the best way, because then it's clear where $username got its value.