<?php
$di->set('usersRepository', array(
'className' => 'Phalcon\Repositories\UsersRepository'
));
$di->set('UsersController', array(
'className' => 'UsersController',
'arguments' => array(
array('type' => 'service', 'name' => 'usersRepository')
)
));
class UsersController extends AbstractController
{
/**
* @var Phalcon\Repositories\UsersRepository
*/
private $usersRepository;
/**
* @param $usersRepository
*/
public function __construct($usersRepository)
{
$this->usersRepository = $usersRepository;
}
public function registerAction($user)
{
$this->usersRepository->create($user);
}
public function listusersAction()
{
var_dump($this->usersRepository->findById(1));exit;
}
}
class UsersRepository implements UsersRepositoryService
{
/**
* @var Users
*/
private $users;
public function __construct()
{
$this->users = new Users();
}
public function create(array $user)
{
$this->users->save($user);
}
public function find()
{
}
public function findById($id)
{
return Users::findFirst($id);
}
public function findByEmail($email)
{
}
public function updateById($id)
{
}
}
And my model is Users with basic fields like username, password etc.