Since Kernel version 3.2 it's possible to use a Repository class in your persistence layer. The repository implements the repository pattern, which means you have clear separation between business and persistence layers. Propel entities are not allowed outside the persistence layer. We are using transfer objects instead. This separation enables switching to different database systems or ORMs, you could even use NOSQL to store your data.

Each module must have the Repository class in Persistence/ModuleNameRepository. The repository must extend \Spryker\Zed\Kernel\Persistence\AbstractRepository which will provide a few helper methods when working with Propel entities.

See Blog module for reference - it was build using the Repository. For example, BlogRepository class:

        use Spryker\Zed\Kernel\Persistence\AbstractRepository;

        * @method \Spryker\Zed\Blog\Persistence\BlogPersistenceFactory getFactory()
        class BlogRepository extends AbstractRepository implements BlogRepositoryInterface
           * @param string $firstName
           * @return \Generated\Shared\Transfer\SpyBlogEntityTransfer
          public function findBlogByName($firstName)
              $customerQuery = $this->queryBlogByName($firstName)

              return $this->buildQueryFromCriteria($customerQuery)->find()[0];

Related Spryks

You might use the following definitions to generate related code:

  • Add Zed Persistence Repository
  • Add Zed Persistence Repository Interface
  • Add Zed Persistence Repository Interface Method
  • Add Zed Persistence Repository Method

See the Spryk documentation for details.


See also:


Last review date: Mar. 21st, 2018