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


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:

Thank you everybody so much :)