Monday, 15 March 2010

Where to put a separate business logic class or classes in CakePHP 3? -


I am preparing a new app and I am planning to use KPPHP 3. Usually when a PHP MVC framework KPPHP, codeigner) I have set a different category that represents the business layer or service level (depending on which word you want to use). Thus, stack:

- view

- controllers [actually only a part of the ideas; Code-Back to C # Land]

- Business Layer [where business logic goes, because business logic spreads many domain items and is not suitable for a model / DAO]

< P> - Model [aka data access object]

... moving between layers with domain objects (now "unit" in cake php3).

I think that cake PHP 3 is still no concept of a business layer in the default structure, which is disappointing but hardly difficult. But after that, my question is not really a pedestrian: this is where I keep MyBusinessLayer.php? In Cake PHP 2 I put it in app / lib, and it would have loaded with

  app :: import ('Lib', 'Mibnnessale');   

What is the equivalent in KPPHP 3, and how do I load it? I realized that I could touch any old place and need_once (), but I wonder if there is a way that coin is consistent with PHP standards. This question is easily ten-line utility class, but in my case it is applicable at the professional level.

For your business layer src directory example, you have Can be a folder called src / core or src / MyBusiness or you may have multiple folders such as src / command source / handler , it is up to you to know how to architecture your application, besides accessing data in a web app service or database.

src If the correct namespace is given then it will be loaded automatically. Src / MyBusiness / BusinessRules.php Name Location App \ MyBusiness

  // Class BusinessRules {...}  

Can load from second usage keyword:

  // Use any other file in the app \ MyBusiness \ BusinessRules; ... $ rules = new business rule ();  

KPHP does not make assumptions for you, when they talk about these types of objects, because they are usually very specific for your application. It offers different types of devices that can help you create a better architecture with a faster and less code. For example configurable implementations by using the event system for appet-oriented programming or archive configuration attributes for the library to work with data using a functional approach.


No comments:

Post a Comment