Skip to content

Latest commit

 

History

History
59 lines (35 loc) · 1.04 KB

File metadata and controls

59 lines (35 loc) · 1.04 KB

Repository

setup

  • create Repository Folder at /app/Domain
  • create AppRepository.php at /app/Domain/Repository

or copy Sugar/code_snippets/Domain/Repository 到 /app/Domain

AppRepository.php

the AppRepository class is the parent class to all of your Repository. AppRepository itself extends the SuperAppRepository class included in the Sugar/Vendor/

<?php
App::uses('SuperAppRepository', 'Sugar.Vendor');
class AppRepository extends SuperAppRepository{

}

use Repository in Aggregate

Mostly, Repository use in Aggregate or Service

// will load App/Domain/Repository/Main/Abc.php and return instance
$postRepo = \SugarLoad::get('Repository/Main/Abc');

// call Repository function
$lastPost = $postRepo->getLastPost();
     

Repository

<?php
namespace Domain\Repository\Main;
\SugarLoad::load('Repository/AppRepository');

class PostRepository extends AppRepository {

    public function somefunction(){  
      //Repository logic goes here..
    }
}

Repository Methods

Repository Attributes