由 Edward Hieatt 和 Rob Mee 开发:使用类似集合的接口在域和数据映射层之间进行中介,以访问域对象。

dev-master 2015-09-18 09:49 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:42:15 UTC


README

Phalcon框架的通用仓库

将名为 'repository '的文件夹移动到您的项目中的某个位置。在我的例子中,它将是 vendor。然后,在您的服务文件中

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

在某个控制器中

/**
 * 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;

}