specializing in digital media technologies

Digital Media and Communications Insights, Inc.


Larry Ullman's Blog

Configuring Yii

This entry is part 3 of 8 in the series Learning the Yii Framework

This is the third post in my series on Yii, my favorite PHP framework. In the first, I show how to download and test the framework itself. In the second, I show how to create a basic Web application. In this post, I discuss how you’ll want to configure your Yii-based application, including handling errors, adding components, and establishing a database connection. This post does assume you have an existing application to work with; if you don’t, follow the steps in the previous two posts.

There are a couple of ways you can configure how your Yii application behaves. For the most part, you’ll do this through the config/main.php file, but first I want to talk about the index.php file, created in the root of your Web application directory. This is a “bootstrap” file, meaning that all user interactions actually go through it. For example, showing an employee record might be through the URL www.example.com/index.php/employee/show/id/34 and updating a department record might involve submitting a form to www.example.com/index.php/department/update/id/3. Both URLs request just that one PHP script.

The index.php file is generated when you use the command-line yiic script. There’s only five lines of non-commented code in it. The first identifies the location of the Yii framework:

$yii=dirname(__FILE__).'/../framework/yii.php';

The path indicated should be correct, but you can change this if you move the framework or the index file.

The second identifies where the configuration file is:

$config=dirname(__FILE__).'/protected/config/main.php';

Edit for Yii 1.1: The framework now creates two bootstrap files: index.php and index-test.php. They are exactly the same except that index-test.php includes a different configuration file: /protected/config/test.php instead of /protected/config/main.php. However, the test configuration file just includes the main configuration file, then also enables the CDbFixtureManager component, which is used for unit testing.


The default behavior is to put the protected directory, where all the application files reside, in the same directory as the index file. My inclination is to move it outside of the Web directory, like so:

Modified Yii Layout

Modified Yii Layout

In such a case, I edit my index.php file to read:

$config= '../protected/config/main.php';

Note that it’s perfectly reasonable to move the location of your application files (i.e., the protected folder), but you should not change the names or structure of the folders found within the protected directory.

The next line of code turns on debugging mode. You’ll want debugging enabled when developing a site, but disabled once live. To do that, remove or comment out this:

defined('YII_DEBUG') or define('YII_DEBUG',true);

I normally just comment it out, so that I can re-enabled debugging later. Or you can change it to something like this, so that you can add debugging to a page on the fly:

if (isset($_GET['debug'])) define('YII_DEBUG', true);

If you do that, then to debug any page on the fly, change the URL from, for example,www.example.com/index.php/site/contact to www.example.com/index.php/site/contact/debug/true.

The last two lines of the bootstrap file include the framework and start the application. Don’t mess with these!

require_once($yii);
Yii::createWebApplication($config)->run();

And that’s really all there is to do in the index.php page. Most of the configuration occurs in the main.php configuration file, found within the protected/config directory (see the above image). There’s also a console.php config file, but that’s for a command-line version of the application. I won’t discuss that here, but you would edit it if you have command-line scripts associated with your application.

The configuration file returns a multi-dimensional array of information, some of which is pre-defined. You do want to make sure that the proper syntax is maintained as you edit this. For starters, you’ll want to change the name of the application, which is used in the default HTML design, in page titles, and so forth:

'name'=>'Wicked Cool Yii Site',

You can also specify the default controller, which has a default value of “site”. In other words, if no controller is specified in the URL, the site controller will be called. To change that to a different controller, add:

'defaultController' => 'login',

Note that this particular line will not work out of the box as only the site controller exists. But you would make this change if you had created a protected/controllers/LoginController.php file (or if any controller file exists for whatever you make be the default).

Next, under the components section of the returned array, you’ll almost always want to establish the database connection (unless you’re not using a database, of course). To do so, return an array that includes a connection string, a username, and a password:

'db'=>array(
    'connectionString'=>'mysql:dbname=test',
    'username'=> 'user',
    'password'=> 'pass',
),

The connection string is a DSN (Database Source Name), which has a precise format. It starts with a keyword indicating the database application being used, like mysql, sqlite, pgsql (PostgreSQL), ssql (Microsoft’s SQL Server), or oci (Oracle). This keyword is followed by a colon, then, depending upon the database application being used, and the server environment, any number of parameters, each separated by a semicolon:

  • sqlite:/path/to/dbfile
  • mysql:host=localhost;dbname=test
  • mysql:port=8889;dbname=somedb
  • mysql:unix_socket=/path/to/mysql.sock;dbname=whatever

Indicating the database to be used is most important. For me, when using MAMP on Mac OS X, I had to set the port number as it was not the expected default (of 3306). On Mac OS X Server, I had to specify the socket, as the expected default was not being used there. Also do keep in mind that you’ll need to have the proper PHP extensions installed for the corresponding database, like PDO and PDO MySQL.

A component that I normally add to the configuration is urlManager:

'urlManager' => array(
    'urlFormat'=>'path'
),

This component changes URLs to be more search engine and user-friendly. For example, the default URL for a page could be something like www.example.com/index.php?r=site/contact, but  urlManager will turn that into www.example.com/index.php/site/contact. Note that you only need to include the component. Once you’ve done that, URLs will be properly formatted (assuming you use the right Yii components to create the URLs) and handled. If you want to take this further, it’s possible to configure urlManager, along with an Apache .htaccess file, so that index.php no longer needs to be part of the URL.

Within the log component section, I add CWebLogRoute. This is a wonderfully-useful debugging tool that adds tons of details to each rendered page. Here’s the code for the config file:

'log'=>array(
    'class'=>'CLogRouter',
    'routes'=>array(
        array(
            'class'=>'CFileLogRoute',
            'levels'=>'error, warning',
        ),
        array (
            'class' => 'CWebLogRoute'
        )
    ),
),

And here’s an example output:

Web Log Output

Web Log Output

As you can tell, editing and adding components is where a lot of the configuration takes place. The ones I’ve highlighted are just the most immediately important, in my opinion, but there are certainly others, involving caching, security, themes, and more. One cool feature of Yii is that not all named components will be loaded for every request. Some, like the logging components are, but others are only loaded when required, thereby minimizing the performance impact of using many components.

Finally, towards the end of the default configuration file you’ll find the adminEmail parameter. Change this to your email address, so that you receive error messages, contact form submissions, whatever:

'params'=>array(
    'adminEmail'=>'whatever@example.edu',
),

And that’s a quick intro to configuring your Yii application. As always, thanks for reading and let me know if you have any questions or comments. In my next post, I’ll discuss a database design I’ll use in subsequent posts. After that, I’ll show you the magic: auto-generated Models, Views, and Controllers using Yii’s command-line tools.

Series Navigation«Getting Started with the Yii FrameworkDefining Databases for the Yii Application»
Filed under: MySQL,PHP,Web Development — Tags: , ,

55 Comments »

  1. If we enable debug as “if (isset($_GET['debug'])) define(‘YII_DEBUG’, true);”, I think this will allow web site visitors or malicious software to enable debug for pages they visit.

    Comment by Chamal — November 18, 2009 @ 12:12 am

  2. Thank you for pointing this out and you’re absolutely correct. Two things: first, you can change ‘debug’ to whatever to make this less obvious. Second, in my mind, I would use this only to allow me to test pages I’m tweaking on a live server. So what I’m thinking in my example is that for 99.9% of the pages in a site, enabling debugging wouldn’t do a thing, as the pages would be working just fine and there’d be no errors to report. For that other small percent of the time, you’d have to know that this debugging key exists and that such and such page would reveal something potential useful.

    Thanks again! Larry

    Comment by Larry — November 18, 2009 @ 10:15 am

  3. Hi Larry,

    I’m busy working through your Yii blog entries (already worked through the MVC ones) and find them extemely useful.Thank you very much for your effort on this.

    I do my development on a dev PC and then deploy the finished product to the actual prod Web server. It is very useful to have the debugging switched on on the dev PC but dangerous on the prod server.

    Although I’m still in the beginning stages of learning Yii, I’m sure that it would be possible to code a check that would check whether the page is called on the dev PC or on the prod server and to switch on the debug mode only when running on the Dev PC?

    Keep up the good work.

    Gerhard

    Comment by Gerhard — December 16, 2009 @ 1:24 pm

  4. Hello Gerhard,

    Thanks for your comments. As debugging is enabled in the bootstrap file, what I would normally do is just have one version on my local server with debugging enabled and another on the real server with debugging disabled. As this script will never be changed again, you don’t have to worry about maintaining two different versions. But if you’d like to create a flexible solution, you could check the value of a $_SERVER variable, like $_SERVER['HTTP_HOST']. IF that starts with ‘localhost’, then use debugging mode.

    Hope that helps,
    Larry

    Comment by Larry — December 17, 2009 @ 9:29 am

  5. Hi Larry,

    You write, “The default behavior is to put the protected directory, where all the application files reside, in the same directory as the index file. My inclination is to move it outside of the Web directory…”.

    What do you do when you have more than one yii project? I presume the framework file remains the same (i.e. nothing is modified there, so all new instances can point to the same file). However, the protected file would be specific to the project. Do you rename the protected file for each project -e.g. acmeProtected? And, modify the index.php: ../acmeProtected/config/main.php?

    Thanks,

    Daniel

    Comment by Daniel Shanahan — January 25, 2010 @ 6:24 am

  6. Hello Daniel. If you have more than one Yii project, my assumption is those would be in entirely separate directories. I can’t imagine why you’d have separate Yii projects in one directory, thereby having a conflict with similarly named protected folders, not to mention index.php files. For example, for one client I created three different sites, all Yii based. Each is in its own directory with its own URL set to point there. They all share the same framework folder but have separate index files and protected directories.

    Comment by Larry — January 25, 2010 @ 5:16 pm

  7. Hi Larry. Sorry – I’m still a bit confused. From the screenshot above (http://blog.dmcinsights.com/wp-content/uploads/2009/11/yii_3_1.png) it appears that the framework file and protected file are siblings. If the protected file remained in the project directory (e.g. htdocs/yiiACME/protected), I can see how there would be no conflicts with other projects. However, in the screenshot and text above, it appears that the protected file is moved “outside of the Web directory.”

    If there is more than one project than it seems to me that there would be more than one protected file at this level of the directory (presuming all the projects can point to the one framework file, so no need to duplicate that file).

    Am I misunderstanding this? It could be that I don’t quite understand MAMP enough to grasp this concept.

    Thanks,

    Daniel

    Comment by Daniel Shanahan — January 25, 2010 @ 9:41 pm

  8. Yes, the framework folder and protected folders are in the same directory, which is outside of the Web root. Both are used by the project in the htdocs folder. I’m still confused by what you mean when you suggest there’d be more than one project in a directory. When I think of a project and am using that term, I’m thinking of a Web site. This also means one directory, one site/project. You’d never have multiple sites served from the same directory. Does that make more sense?

    Comment by Larry — January 25, 2010 @ 10:35 pm

  9. Thanks, Larry. I think I’m just not clear on how MAMP works. I’ll google around a bit for that. Otherwise, your answer helps – namely, there is really no need to rename the protected file.

    Again, thanks for these yii tutorials; they are very helpful.

    Comment by Daniel Shanahan — January 26, 2010 @ 12:17 pm

  10. You’re quite welcome and thanks for the nice words. I’m sorry I’m having a problem understanding what you’re asking. I’ll try again. MAMP is just a package for Mac OS X that provides an Apache, MySQL, and PHP configuration. I’ve been using it on Macs for sometime because it’s very easy and doesn’t affect the tools that come with the OS. You can tell MAMP what the root Web directory should be and that’s easy to change. So what I do is this: in my Sites folder, I put the Yii framework. Then I create a directory for a new site (which will go at http://www.example.com). In that directory I put my protected directory and the htdocs dir, which will be the Web root for that site. Then I tell MAMP to use that htdocs dir for the Web root while I’m working on that project. When I go to do another site (www.example.edu), I create a new dir for that project, with a new protected folder and a new htdocs folder in there; then I tell MAMP to use that new htdocs folder for the Web root. Does that make sense?

    Comment by Larry — January 26, 2010 @ 3:42 pm

  11. Thanks, Larry. Yes, it is starting to make more sense. I appreciate your patience!

    My set up is somewhat basic. In my Sites folder I have all the non-PHP web projects. In my MAMP folder I have the PHP projects. So, my URL for local files is either http://localhost/~Daniel/ (for Sites folder) or http://localhost:8888/ (for MAMP folder). Moreover, the files being served through my MAMP installation are all within the htdocs folder (Application/MAMP/htdocs/projectFolderName). So, I could theoretically have Application/MAMP/htdocs/yiiProjectA and Application/MAMP/htdocs/yiiProjectB and when I move the protected file outside of the web root I would have two files named “protected” in the same directory, siblings of the htdocs which, of course, I would not be able to do.

    I now get that this is not what you are doing. If I understand you correctly, your path is something like this: Sites/Yii/ProjectA and Sites/Yii/ProjectB, etc. Most of the screencasts I have watched on MAMP installation have simply left the configuration to http://localhost:8888/ which is what i have done on my machine.

    I’ll try to combine my two locations for localhost to just one. I think what I need to do is change my MAMP preferences to Apache port 80 and MySQL port 3306 and change the Apache document root to /Users/Daniel/Sites/. Then, I think I’ll need to move the project files from Application/MAMP/htdocs/ to /Users/Daniel/Sites/. After that, I believe that I can then have Sites/Yii/ProjectA and Sites/Yii/ProjectB.

    Again, Larry, thank you for your patience.

    Daniel

    Comment by Daniel Shanahan — January 27, 2010 @ 4:35 pm

  12. You’re quite welcome. Glad you’ve got a sense of it now. You don’t need to change the port numbers, though. Just change the Apache document root in MAMP as needed.

    Comment by Larry — January 28, 2010 @ 4:54 pm

  13. I have just started with Yii and in following your suggestion to add ‘urlManager’ and ‘log’ entries to main.php I get errors.

    Property “CWebApplication.urlManager” is read only.
    Property “CWebApplication.log” is not defined.

    Is there additonal configuration that I need to do and if so for a newbie it would be useful to include that here.

    Thanks

    Richard

    Comment by Richard Shapland — January 29, 2010 @ 5:16 am

  14. What version of the Yii framework are you using? What is the exact code you used?

    Comment by Larry — January 29, 2010 @ 2:09 pm

  15. Hi thanks fortaking the time to write this tutorial. It help a lot. I do have one question…upon setting the following;

    ‘defaultController’ => ‘login’,

    I get the following error;

    Unable to resolve the request “login”

    Have I missed something?
    I’m a newbie…any help or point in direction appreciated

    Comment by Sii — February 6, 2010 @ 8:42 pm

  16. I think the defaultController setting has changed, so that you want to do this instead:

    ‘defaultController’ => ‘site/login’,

    Right? BTW, outstanding discussion on a great framework!

    Robert

    Comment by Robert — February 8, 2010 @ 5:17 pm

  17. Richard – I just had the same problem with urlManager and figured out where the error was. You have to put the directive inside the components array. I put it outside, and I imagine you probably did too, since we both got the same error. Putting it inside works correctly for me.
    Robert

    Comment by Robert — February 8, 2010 @ 5:40 pm

  18. Thanks, Robert, for the nice words. I haven’t yet tested Yii 1.1 myself, but I don’t think site/login would be an appropriate value. The controller would be identified by just “site” (equating to SiteController). The default action within the controller could specify “login”.

    Comment by Larry — February 8, 2010 @ 6:41 pm

  19. Thanks, Robert, for adding that note. Richard never replied, so I wasn’t sure what the problem was.

    Comment by Larry — February 8, 2010 @ 6:42 pm

  20. I’m not sure, it could be that my configuration isn’t quite right, but under the protected/views directory I have:

    department
    employee
    layouts
    site

    so in 1.1 there is no /login view, or is that expected?

    Robert

    Comment by Robert — February 8, 2010 @ 7:59 pm

  21. Trying to set the defaultController to just login generates an error:

    exception ‘CHttpException’ with message ‘Unable to resolve the request
    “login”.’ in /var/www/framework/web/CWebApplication.php:324
    Stack trace:
    #0 /var/www/framework/web/CWebApplication.php(120):
    CWebApplication->runController(”)
    #1 /var/www/framework/base/CApplication.php(135):
    CWebApplication->processRequest()
    #2 /var/www/yii/tut1/index.php(11): CApplication->run()
    #3 {main} REQUEST_URI=/yii/tut1/index.php

    Comment by Robert — February 8, 2010 @ 8:03 pm

  22. I just downloaded Yii 1.1 and starting running through my tutorial. I haven’t had problems with the suggestions in the above. There is no login view folder, as the login functionality is defined as part of site.

    Comment by Larry — February 8, 2010 @ 10:01 pm

  23. Correct. Because you probably don’t have a LoginController. If you set the defaultController to ‘site’ or ‘department’ or ‘employee’, that should work for you. I just tried this myself, using ‘site’ (because I hadn’t yet created the departments and employees) and had no problems. Of course, ‘site’ is the default controller anyway.

    Comment by Larry — February 8, 2010 @ 10:03 pm

  24. Robert, I’m rereading this to make sure it’s current for the latest version of Yii. In doing so, I saw that I didn’t make it clear that you can’t just change the defaultController without having already created the actual new default controller. I added a note saying as much. My apologies for the confusion!

    Comment by Larry — February 9, 2010 @ 9:18 am

  25. [...] learning Yii and updating it for the latest version. Here’s what I found so far…From my Configuring Yii [...]

    Pingback by Larry Ullman's Blog » Yii Framework 1.1 Updates — February 9, 2010 @ 9:51 am

  26. Thanks for all the updates Larry. Looking at the current directory structure that yiic creates, it’s probably no longer any advantage to move /protected out from under webroot if you’re using Apache. The /protected folder contains a .htaccess file that blocks access to the files.

    Comment by Robert — February 10, 2010 @ 1:06 pm

  27. You’re welcome, Robert. I’m still working through them all. Not too many changes, which is a good sign. It’d be bad if version 1.1 of a framework broke code that worked in version 1.0! As for the .htaccess in the protected directory, it was created in previous versions, too. I just like to be over-protective of such things.

    Comment by Larry — February 11, 2010 @ 10:41 am

  28. Using Yii v1.1 I get an error “Property “CWebUser.urlManager” is not defined” when I add:

    ‘urlManager’ => array(
    ‘urlFormat’=>’path’
    ),

    Comment by GargantulaKon — February 28, 2010 @ 10:22 am

  29. Never mind, I accidentally put it in the ‘user’=>array(. Oops. My links do not work though, but I am trying with ‘showScriptName’=>false, and a modified .htaccess file. If I add index.php, it works fine. I see my Apche log says that it does not reconginix RewriteEngine On. I am using Apache 2.2.11 on WAMP.

    Comment by GargantulaKon — February 28, 2010 @ 10:39 am

  30. Sorry, never mind again. I hope this helps someone else. In your WAMP server, make sure you enable the Apache module for “rewrite_module” and then try it again. I am surprised it is not enabled by default.

    Comment by GargantulaKon — February 28, 2010 @ 10:46 am

  31. Thanks for sharing. If you’re using IIS, you’ll need to enable rewrite using a Web.config file (just so that others might benefit).

    Comment by Larry — February 28, 2010 @ 4:43 pm

  32. for me in yii-1.1.0.r1700 there were not obvious, but it works now, I did:
    – defaultController works with: ‘defaultController’ => ‘site/login’, (eg. right after ‘name’=>…,)
    – CWebLogRoute is already in config file so you only need to remove comment from line 52,56
    – ‘urlManager’ => array(‘urlFormat’=>’path’), should be inserted into ‘components’ subarray(!) (eg.after line 23)
    —-
    btw. great blog Larry thank you!

    Comment by sis — February 28, 2010 @ 5:30 pm

  33. ‘so that index.php no longer needs’
    and it is easy to remove from links
    with configuring showScriptName, like:
    ‘urlManager’ => array(
    ‘urlFormat’=>’path’,
    ‘showScriptName’=>false
    ),

    Comment by sis — February 28, 2010 @ 6:02 pm

  34. Once again, great tutorial!

    Thanks!

    Comment by Eduardo Russo — February 28, 2010 @ 6:13 pm

  35. You’re welcome. Thank you for the feedback!

    Comment by Larry — February 28, 2010 @ 8:25 pm

  36. You’re welcome. Thank you!

    Comment by Larry — February 28, 2010 @ 8:26 pm

  37. Hi,Larry

    can you help me?

    I want to create my own log file in yii, how should i create?

    need your help!

    Comment by Harshal M.Joshi — March 24, 2010 @ 7:07 am

  38. Do you mean a log file like an error log file?

    Comment by Larry — March 24, 2010 @ 7:51 am

  39. How to insert an image in the title, like a logo, could you tell me?

    Comment by Diego Ramos — March 30, 2010 @ 9:23 am

  40. Oh GOD! MS SQL Server doesnt accept charset…. what can i do to format my data?

    Comment by Diego Ramos — March 30, 2010 @ 3:44 pm

  41. Could you specify what you mean by the title?

    Comment by Larry — March 30, 2010 @ 5:36 pm

  42. Just to confirm, you mean MS SQL Server as in Microsoft’s SQL Server, right? And it doesn’t support charset? That can’t be right.

    Comment by Larry — March 30, 2010 @ 7:09 pm

  43. to Diego Ramos: probably you need this: http://en.wikipedia.org/wiki/Favicon

    Comment by Nikolai — April 6, 2010 @ 9:54 am

  44. Ah, probably what he was talking about. I was over-thinking it. Thanks!

    Comment by Larry — April 7, 2010 @ 9:12 am

  45. I used this approach to set the YII_DEBUG and YII_TRACE_LEVEL constants:

    In my localhost VirtualHost directive, I added this


    SetEnv APPLICATION_PATH “development”

    In index.php, I did this

    if (isset($_SERVER['APPLICATION_ENV']) && $_SERVER['APPLICATION_ENV'] == “development”) {
    define(‘YII_DEBUG’,true);
    define(‘YII_TRACE_LEVEL’,3);
    }

    Hope that helps someone.

    Comment by Dave Joyce — April 29, 2010 @ 1:37 am

  46. Excellent suggestion. Thanks for the input!

    Comment by Larry — April 29, 2010 @ 8:07 am

  47. Hi,
    Larry am very happy to see such tutorial for us who are beginners to the world of OOP and MVC pattern. I have just started working with yii framework and am moving my site to this framework and my question is which directory should i place my HTML, css and JavaScript codes since right now am not into something to do with the database but latter on i will, what i mean my pages are just static and i really want to integrate with yii. Thanks again for this tutorial as in near future i going to apply the same principal you have used to build an application for news management.

    Comment by bonny — May 13, 2010 @ 10:19 am

  48. Thanks. Good luck with your project!

    Comment by Larry — May 13, 2010 @ 4:18 pm

  49. Hi,
    I had asked a question about yii framework. In which directory do i need to put my html, javascript and css for my static website am developing since i have decided to move to yii framework? is it in the theme or where? Thanks i advance again for this tutorila.

    Comment by bonny — May 14, 2010 @ 12:57 am

  50. Oh, sorry I missed that! Okay, your JavaScript and CSS goes in the Web directory, because it’ll be referenced in your HTML and the browser will request it when it sees those references. All your images and other media also go in the Web directory. The HTML goes in the protected/views folder for your Yii product. The index.php file will pull them out of there.

    Comment by Larry — May 14, 2010 @ 7:55 am

  51. The WebLog of Yii should refer to Python Django implementation to direct the debug log via HTTP header, rather than in HTML, so people can use Firebug to debug the server code.

    Comment by allankliu — May 27, 2010 @ 10:30 pm

  52. Not sure if this helps, but rearranging your yii framework layout is simple, and simplifies where you place your files. This setup also lends itself to enabling multi-site setups.

    For example, if you arrange your layout like:

    sites/
    framework <– yii framework folder
    base/
    caching/

    site1.com/
    private/ <– renamed from 'protected'
    controllers/
    models/

    public/ <– domain pointer here
    css/
    img/
    index.php <– modified front-controller
    .htaccess
    site2.com/

    Be sure to change the paths in your index.php/index-test.php file like so:

    $yii = dirname(__FILE__).'../../../framework/yii.php';
    $config = dirname(__FILE__).'../../private/config/main.php';

    Now, you place all your web accessable files in the public folder like:

    public/
    css/
    styles.css
    images/
    javascript/

    NOTE: This is more of a production setup, and requires an understanding of virtual host setups to point your domain to the 'public' folder for each site you setup.

    Comment by Geoff — July 13, 2010 @ 2:51 pm

  53. Thanks to your detailed post and your suggestions. Storing the framework directory in a common location so that multiple sites can use it (assuming you have multiple sites on the same server in which you can do this) makes a lot of sense. I also am likely to place the protected directory outside of the Web document root. I’m curious, however, what you think the benefits are to renaming the “protected” directory as “private” and, more importantly, moving the “controllers” and “models” folders out of “protected/private”? You have to reconfigure Yii’s basic assumptions (as to where those two directories are) to make that work. I’m not sure why someone would want to do that.

    Comment by Larry — July 14, 2010 @ 8:16 am

  54. The name change from ‘protected’ to ‘private’ is for symantics *only* and is presented here to highlight the ease of arranging your yii directroy structure. To some it tends to be easier to understand opposites(public/private vs protected/public).

    Refering the controllers and models, that was a comment snafu – I do not move controllers or models outside the ‘protected’(private in the above example) folder! They have to remain in the protected folder for everything to work correctly or more modifications are required and this is nolonger a simple solution.

    The spaces were striped out in the comments, doh!

    Lets try it this way:

    sites/
    …framework/ <– yii framework folder (can be renamed)
    ……base/
    ……cache/
    ……ect…

    …site1.com/

    ……protected/ <!– can be renamed
    ………controllers/
    ………models/
    ………ect…

    ……public/ <– domain points here (secure)
    ………assets/
    ………css/
    ………images/
    ………themes/
    ………index.php <– modifed index file
    ……….htaccess

    …site2.com/
    ……protected/
    ……public/

    —-
    In this example the index.php file is altered to reflect:

    $yii = dirname(__FILE__).'../../../framework/yii.php';
    $config = dirname(__FILE__).'../../protected/config/main.php';

    Hope that clears things up.

    Comment by Geoff — July 15, 2010 @ 10:20 am

  55. It clears things up very much. Thanks! And thanks again for your input. One thing I do is create a folder named yii_framework that’s accessible to multiple sites. Within that folder I put the actual Yii framework folder. Plus I also put an empty text file in there whose name is the version of the Yii framework that’s there. That way it’s obvious which version of which framework is there, but upgrading the framework wouldn’t mandate any changes in actual site code.

    Comment by Larry — July 16, 2010 @ 7:28 am

RSS feed for comments on this post. TrackBack URL

Leave a comment




If you have a question, are seeking information, want to download files, or generally have any need related to a specific book, please make sure you are using the correct link. Check both the title and the edition.