Revision #5 has been created by andy_s on Mar 24, 2010, 8:22:53 AM with the memo:
Fixed typos
« previous (#4) next (#6) »
Changes
Title
unchanged
Organize directories for applications with front-end and back-end using WebApplicationEnd behavior
Category
unchanged
Tutorials
Yii version
unchanged
Tags
unchanged
Content
changed
[...]
login.php
~~~
Front-end SiteController and all front-end views are files generated by yiic tool. You have to create back-end SiteController and back-end views by yourself (or just copy and modify front-end ones).
> Note: Since a new full path to front-end layouts is "application.views.front.layouts", you have to edit "column1.php" and "column2.php" files to render "application.views.front.layouts.main" as a parent layout. Also set Controller's (protected/components/Controller.php) layout property to 'column1'.
Now let's create different config files for both ends. Since these files usually have much in common, we will "inherit" them from the main.php config:[...]
By default, Yii will try to find controllers and views in protected/controllers and protected/views directories respectively. We have to change this behavior and force Yii to search controllers and views in the "back" or "front" subdirectories depending on the currently running end.
Actually we can do it in the -end's config file by setting "viewPath" and "controllerPath" properties, but what if we are going to have some modules like News, Articles, etc.? We'll need to set these properties for them too!. We can also have some back-end modules which don't need such separation.
Here comes the Yii magic. In protected/components directory create a file "WebApplicationEndBehavior.php" with the following contents:[...]
Note that in this case the module's controllers and views paths must be organized as shown before.
If a module doesn't need a separation
to
f back-end and front-end controllers and views, then just omit
the onModuleCreate event's raising.
Finally, let's protect back-end by creating a parent controller for all back-end controllers:[...]
webroot/protected/controllers/back/SiteController.php must extend this controller to perform access checking.
Everything's done. New index.php and backend.php files look likare:
<strong>webroot/index.php:</strong>
```php[...]