-
Notifications
You must be signed in to change notification settings - Fork 63
Differences between stock Yii projects and Web Store 3
##Introduction
In the course of migrating Web Store 3 to the Yii framework, we faced the goals of moving existing code into a new MVC framework while attempting to stay as true to the "Yii" way of doing things as possible. In certain situations, we had to deviate slightly or make changes to accommodate the project.
Some of these changes were required simply to implement the features necessary. Other changes were done because we are serving two simultaneous audiences -- the end user shopper and the features they need to shop, and the web designers and programmers who wish to modify and extend the stock Web Store for their own customers' projects.
It is our expectation that those changing Web Store would first and foremost rely on the Yii documentation for how-to questions. However, since their documentation always assumes the default Yii methodology, we needed to document where our program differs so you don't get confused.
###File Structure
In a stock Yii project | In Web Store 3 |
All controllers are located in the /protected/controllers directory | We have placed our controllers under /core/protected/components/wscontrollers
If you wish to add your own controllers, or extend one of ours, follow the directions at Extending a Controller |
All program configuration is in /protected/config/main.php | For installation, we ship with a file called /core/protected/config/_main.php which at installation-time is copied, the copy being /config/main.php. Since this file is created as part of install, we will never overwrite or change /config/main.php during an upgrade. You are free to modify /config/main.php, which actually you will have to do if you add custom extensions, etc.
Additionally, there are several places where instead of putting the configuration in /config/main.php, it references a subfile. For example your database connection info is in /config/wsdb.php and this is simply referenced in main.php. This means in case of tragedy where we have to rebuild main.php, settings such as database, email, encryption keys, etc, are in their own files under /config Finally, in order to make Web Store faster, our configuration table xlsws_configuration is exported into a file /config/wsconfig.php which converts these tags into Param fields. (Admin Panel rewrites this file every time you click Save in the panel). This means any configuration key such as ENABLE_SRO can be read as Yii::app()->params['ENABLE_SRO'] (The _xls_get_conf() function simply echos back the param, so either way will work.) |
All view files are in /protected/views |
In order to implement our new Viewsets concept, we don't actually have a /protected/views folder, but rather we create it as a symbolic link to point to whatever set of view files we're using (default: /core/protected/views-cities).
Picking a new viewset in Admin Panel recreates this symbolic link |
Extensions are placed in /protected/extensions |
Web Store has a second folder /custom/extensions and the main.php is designed to look in both folders. The custom folder can be referenced with the shortcut "custom" in Yii dot-notation pathing (http://www.yiiframework.com/doc/guide/1.1/en/basics.namespace) . So just like application.extensions.bootstrap is a dot-notation pointing to /core/application/extensions/bootstrap, you could also place the bootstrap in the custom folder and reference it as custom.bootstrap
Custom extensions can be referenced as custom.extentions.myfolder.myclassfile |
All database table Models are in /protected/models |
Yii comes with a built-in program called Gii which takes your MySQL database schema and creates models based on the table definitions. The original design creates one file for each table, and you are expected to modify this model to add your own class functionality.
The issue with this is if you change you schema and need to regenerate your model, any customization is lost. Web Store 3 has a Yii Extension called Giix which instead creates TWO files for each model, a Base class for each table and then an extended class that originally is empty for each table. The empty models are under /core/protected/models and the base classes live in /core/protected/models/base In this way, you can use Giix to generate table models if your definition changes without losing your custom class. Giix is disabled in the shipping Web Store 3 but can enabled if desired. There are lines in /config/main.php which are commented out, that must be uncommented to use the program. (It should be used to generate models for any new tables you have created, but we do not recommend changing the default tables from Web Store) Note that if you create your own table models, you can place the in /custom/models since the original /core/protected/models folder is read-only. Yii looks in both places and treats the files equally. (They're all loaded at runtime so you don't have to do anything special to access them.) |