Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (50 sloc) 2.14 KB

Overview

Yii applications code is typically grouped into modules by context. In each module there could be grouping by type.

For example, if the application is an online store, contexts could be:

  • Customer
    • Profile
    • Products list
    • Checkout
  • Logistics
  • Delivery
    • Addresses
  • Helpdesk
    • Support
    • Claims
    • Returns
  • Accounting
    • Returns
    • Transactions
    • Taxes

For a "Customer" context, residing under App\Customer namespace, structure would be:

App/
  Customer/                          <-- module namespace
    Entity/
      Customer.php                   <-- entity shared by "Profile" and "Checkout"
    Profile/
      Widget/
        Gravatar.php
      ProfileRepository.php          <-- repository is usually specific to context
      ProfileController.php          <-- "Customer\Profile" entry point
    ProductList/                     <-- module namespace 
      Entity/                        <-- entities specific to "Customer\ProductList"
        Category.php
        Product.php
      ProductsListController.php     <-- "Customer\ProductList" entry point
    Checkout/                        <-- module namespace
      CheckoutController.php

A context may include sub-contexts. If a class is shared by multiple contexts, it is moved to the ancestor of both contexts.

A context may have an entry point known as "action" or "controller". Its job is to take a request instance, pass it to domain layer in a suitable format, and create a response based on what is returned by domain layer.

Besides, Yii applications also have the following:

  • entry scripts: they are PHP scripts that are directly accessible by end users. They are responsible for starting a request handling cycle. Typically a single entry script is handling whole application.
  • services: they are typically stateless objects registered within dependency container and provide various action methods.
  • middleware: they represent code that need to be invoked before and after the actual handling of each request by action handlers.
You can’t perform that action at this time.