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

How can I pass parameters from controller to model?

My controller:

$category = new Category();
$success = $category->getParentCategory($id);

My model:

public function getParentCategory($id){
    $query = $this->modelsManager->createQuery("SELECT * FROM Category WHERE parent_id = :parent_id: AND flag = 0");
    $result = $query->execute(array(
        'parent_id' => $id
    ));
    return $result;
}

but I'm unable to get the id parameter.

Hi there ! You can use findFirstBy<property-name> function

$category->findFirstById($id);

https://docs.phalcon.io/en/latest/reference/models.html

Hi, I mean that I want to get the value of "id" parameter from model. Is it right?

It's better to define the relation between the model and it's parent in both models (see Phalcon MVC Model) then load the parent category's id like below:

$cat = Category::findFirst('id = 1');
$parentCatId = $cat->parentCat->id;
// or
$parentCatId =  Category::findFirst('id = 1')->parentCat->id;

The easiest way to accomplish this is to set up a relationship like @tartanpro suggested. Documentation here: https://docs.phalcon.io/en/latest/reference/models.html#relationships-between-models

Thank you everybody so much :)