Full-fledged Yii demo app for learning purpose

Hi All Yii Aficionados,

I am a freelance software developer (based in India) with more than 15 years of experience in Microsoft technologies. Of late, I have been experimenting with open-source web development stack and the first one I’ve been looking at is LAMP. After getting hold of PHP, I chanced upon Yii while looking for web development frameworks in PHP. I immediately liked it for its power. I decided to learn Yii and have been spending some time with it. The first thing I do when I pick up a new framework is to develop a sample project that is reasonably complex and will let me use some of the important/necessary features of it. Online book store ( I usually call it Digital Library) is the one I develop to gain confidence. I developed it in Yii and wanted to share with you all. To enable all the newbie Yii devlopers to study and learn and for the experienced ones to contribute to make it the most comprehensive tutorial app, I have made it open source and put it in GitHub: (github dot com slash Krish-Chandra slash DL). Please go through the readme file to find out the features that it offers and also for the scope for enhancement.


Now, there are 3 versions of the DL app corresponding to the 3 branches:

  • Version 1(master branch):

  • Uses PHP script file for authorization data and access control filters for RBAC

  • Allows a book to have only one author and category each.

  • Doesn’t support caching

  • Supports database migration

  • Version 2(‘Caching-and-Many-Many-relations’ branch):

  • Uses PHP script file for authorization data and access control filters for RBAC

  • Allows a book to have a maximum of 3 authors and categories each

  • Supports caching

  • Supports database migration

  • Version 3(‘Use-Yii-RBAC’ branch):

  • Uses the database for RBAC


  • There is an admin component for it

[*]Allows a book to have a maximum of 3 authors and categories each

[*]Supports caching

[*]Allows the books catalog to be searched based on title or author

[*]Supports database migration



Krish Chandra

krishchan01 at hotmail dot com

gr8 work,

found you made modules for admin and library.

will check whole afterwards.

Me also thinking for made opensource sample project demo, but haven’t get time.

+1 for this.

address is https://github.com/Krish-Chandra/DL :lol:


This is very good idea and will help the community tremendously. I randomly looked through some of the controllers and noticed that occasionally you are printing html in your controllers. What made you choose to display html in the controller rather then using a view?

Thanks for sharing with us.

after i run i got this error ( ! ) Fatal error: Class ‘Memcache’ not found in C:\xampp\yii\framework\caching\CMemCache.php on line 111

Call Stack

Time Memory Function Location

1 0.0007 336072 {main}( ) …\index.php:0

2 0.0253 1885224 CApplication->run( ) …\index.php:15

3 0.0253 1885224 CWebApplication->processRequest( ) …\CApplication.php:158

4 0.0253 1885224 CApplication->getUrlManager( ) …\CWebApplication.php:135

5 0.0254 1885280 CModule->getComponent( ) …\CApplication.php:501

6 0.0277 2101272 CUrlManager->init( ) …\CModule.php:372

7 0.0277 2101304 CUrlManager->processRules( ) …\CUrlManager.php:205

8 0.0278 2101336 CModule->getComponent( ) …\CUrlManager.php:215

9 0.0299 2246296 CMemCache->init( ) …\CModule.php:372

10 0.0300 2246608 CMemCache->getMemCache( ) …\CMemCache.php:88

11 0.0300 2246816 YiiBase::autoload( ) …\YiiBase.php:0

12 0.0303 2248248 CApplication->handleError( ) …\CApplication.php:421

13 0.0352 2925792 CErrorHandler->handle( ) …\CApplication.php:793

14 0.0352 2925824 CErrorHandler->handleError( ) …\CErrorHandler.php:106

15 0.0354 2938248 CErrorHandler->render( ) …\CErrorHandler.php:238

16 0.0354 2938280 CWebApplication->runController( ) …\CErrorHandler.php:280

17 0.0354 2938280 CWebApplication->createController( ) …\CWebApplication.php:271

18 0.0354 2938344 CApplication->getUrlManager( ) …\CWebApplication.php:311

19 0.0354 2938400 CModule->getComponent( ) …\CApplication.php:501

20 0.0355 2940240 CUrlManager->init( ) …\CModule.php:372

21 0.0355 2940272 CUrlManager->processRules( ) …\CUrlManager.php:205

22 0.0355 2940304 CModule->getComponent( ) …\CUrlManager.php:215

23 0.0356 2942232 CMemCache->init( ) …\CModule.php:372

24 0.0356 2942264 CMemCache->getMemCache( ) …\CMemCache.php:88

Hi bettor,


I echo HTML from the controllers whenever the action is AJAXified.


Krish Chandra


Open the main.php config file in the protected\config folder, locate the following line, comment it out and try:

‘cache’=>array(‘class’=>‘system.caching.CMemCache’, ‘servers’=>array(array(‘host’=>‘’, ‘port’=>11211, ‘weight’=>60))),

hey Krish , nice app

I am going to take a deep look at your app since I am a new Yii developer.

But wich is the username and posword for admin area?

Hi razorfish,


username: administrator

password: admin

Seems like there is a case-problem with the files:




on some systems. (eg. Linux)

They should be:



The proposed paths in index.php are Windows paths also…

Works better with forward slashes on Linux :slight_smile:

And a last thing: the name of the database is also capitalized.

Spelling of database and ‘connectionString’ => ‘mysql:host=localhost;dbname=digital_library’, in main.php should be spelled same way.

As a newbie it took me a few hours to find out. Thought I should share it.


IMO, those changes needs to be applied to the repository, so you’d better fork it and issue a pull request. :)

Even if I didn’t noticed the backslashes, as I’m using Windows, the issue should be solved in this branch:


Pullrequest is already open.

I did not touch the case issues inside the app.

IMO, if it doesn’t break anything on Windows, fix it in the main branch.

Makes sense since 98% of all servers are running on some kind of *nix and thus are case-sensitive.

Well I’m not the owner, I just forked the project and opend a pullrequest to include yii as a submodule. I didn’t noticed the case-sensitivity issue. I just changed the backslashes to forward slashes as I updated the path.

And I found a few other case-sensitivities…

in modules/admin/views/author/index.php 17: ‘zii.widgets.Grid.CGridView’,

should become a lower case: zii.widgets.grid.CGridView’,

same for













I notice that you’ve added ‘RewriteBase /’ in .htaccess. Why did you add this line? With it, a url, like http://localhost:8080/DL/admin, will not work.

What is the issue with backslashes? Since I develop on Windows, I am unable to anticipate the issues on other OSes.

I obv. failed with this, I just changed that on my local system and forgot to remove it from the commit. Would be nice if anyone could revert this, as I’m currently(including the next two weeks) unable to get access to a pc with a working version of git.

Well I’m trying this apps and it seems cool for a beginer like me.

When I delete an Author that has some Books, those books are deleted too.

How is this possible since actionDelete on Author model doesn’t have any piece of code related with the deletion of his books?

Sir why is that i try to install on my local host and created a sample author, publisher, and categories and when i try to add a book, My ISBN always invalid…

Taken care of it!