Skip to content

karborator/generic-repository-phalcon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phalcon-generic-repository

Generic repository for Phalcon-framework

Move the folder named 'repository 'somewhere in your project.In my case it will be vendor. Then, at your services file:

        /**
         * Autoload repository
         */
        include __DIR__ . "/../../vendor/repository/autoload.php";
        
        
        /**
         * Generic Repository
         */
        $dependencyInjector['repository'] = new GenericRepository($config, 'user');

At some Controller :

/**
 * List all created pages
 *
 * @link   /page        - method GET
 * @link   /page/1      - method GET
 */
public function indexAction($id)
{
    if (!empty($id)) {
        echo $this->repository->setModel('Page')->setCriteria(array("id = '$id'"))
            ->mergeResults()
            ->findFirst()
            ->getRelated(array('articles', 'comments'))
            ->returnAs('json');
        exit;
    }
    echo $this->repository->setModel('Page')
        ->mergeResults()
        ->findAll()
        ->getRelated(array('articles', 'comments'))
        ->returnAs('json');
    exit;

}

About

Generic repository for Phalcon-framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages