© 2015 X2Engine Inc.
Introduction To Development
X2CRM is built using the following frameworks. Hence, the majority of necessary knowledge for development in X2Engine can be found in their respective documentation.
Yii Framework is a PHP framework based on the time-tested MVC (Model-View-Controller) design pattern, which is of particular importance in understanding how requests translate to the execution of class methods.
MVC In a Nutshell
How a Request To The Web Application Translates To Execution
A request to the server translates to the instantiation of a controller class. Which controller is instantiated depends upon the route, which contains the first part of the controller class's name with the first letter in lowercase. Then, the method of the class whose name begins with "action" is run based on the action ID of the request URL. As the action runs, it will retrieve data from the database using a model class. Actions which respond with content will then typically make a call to render or renderPartial, methods inherited from the CController class. The view file, specified by the first argument to render or renderPartial, will then be used to display the content (contained in the model) which is then passed back to the client as markup (or json, text, etc.)
Relevant documentation: Fundamentals: Conventions (§5: Directory)
Modifying the codebase requires an understanding of where the relevant files are located. All PHP files used in the web application, which don't belong to the framework, are under the protected/ directory. This directory is not accessible from the web per the access rules defined in the .htaccess file; rather, these files are executed by the framework as the application runs. Within protected are the following directories:
- Miscellaneous classes used throughout the application, especially those which are extended by other classes. Contains its own views folder, which is used for storing templates for Widgets.
- Core configuration files for the web application.
- Base-level controller classes.
- Miscellaneous data files. Currently used to store SQL scripts that are run during installation.
- The designated folder for storing third-party classes.
- Files containing translations of messages within the application (used by Yii::t)
- All core/base level model classes.
- Self-contained modules. Most of the subdirectories here contain modules whose names appear in the main menu. Each subdirectory typically has the same structure as the base application; they each will have directories named controllers, models and views. See Fundamentals:Module in The Definitive Guide to Yii for more information.
- (For the application's use) Temporary files written to by the application
- The designated directory for storing unit tests.
- View files corresponding to base-level controllers.
Typically, when you use a class in Yii, you will never have to use an "include" statement. That is because Yii will automatically recognize when you intend to use a class and automatically load it. Directories can be scanned by Yii to recognize class files for automatic inclusion using Yii::import(). Furthermore, many directories are already imported, so there is no need to call the import method a second time. The bulk of importing in X2CRM is done in ApplicationConfigBehavior.