andy_s, need help with front/backend setup


I followed your instructions in the cookbook for setting up a front/back end structure to my project. The front end works fine so far, but the backend gives me this error upon loading the index page:

Error 404

Unable to resolve the request "admin/index".

It appears to be coming from the front end, even though I’m requesting the back end. What should I look for? Thanks for the help.

Backend url is: http://site/backend.php or http://site/backend.php?r=site/index. There is no admin controller.

Thanks for your quick reply. ‘admin’ is the Apache url rewrite for backend.php. I later realized that Yii’s crud creates pages called admin so I changed the rewrite rule to ‘sysadmin’ but I still get the same kind of error. I’ve been analyzing both the cookbook article and this post but I still don’t get it; please bear with me.

So I decided ok, forget about apache for now and go directly to backend.php using no urlmanager. The app tries to load the backend login page. Next, Yii gives a CException ‘Property “SiteController.breadcrumbs” is not defined’. (Why?, it doesn’t happen on the front end) Ok, I delete the breadcrumbs from the backend login page and can finally login. (I’m using the default admin user that comes with yiic webapp.)

Now I notice that no matter whether I log in through the front or the back end, the home page displayed is the back end. Any ideas? Thanks again.

With this kind of .htaccess I can access my backend part via url "http://site/sysadmin":

AddDefaultCharset utf-8

Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on

# Make the backend accessible via url: http://site/sysadmin.

RewriteRule ^sysadmin$ backend.php

# If a directory or a file exists, use it directly.

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise forward it to index.php.

RewriteRule . index.php

There are no any url rules in the backend or base config files.

Frontend SiteController and backend SiteController are different controllers. Probably, in your case the former extends Controller (not CController which does not have such property), and the Controller class has property “breadcrumbs” so everything works fine. Backend SiteController extends BackEndController extends CController, so it doesn’t have breadcrumbs property too (you should add it manually).

I tried to reproduce your last problem but failed. I added user component in the base config file with ‘loginUrl’=>array(‘site/login’) and also added actionLogin and actionLogout to both SiteControllers. Everything works as expected…

Hi again, and thank you for your help:

You’re right about Controller and CController, but forget about the breadcrumbs in the backend as I don’t need them.

I’m afraid my hosting provider ( is not helping because I made the .htaccess changes you suggested (’^sysadmin&’ instead of ‘^sysadmin’, and ‘. index.php’ instead of ‘^.*$ /index.php [L]’) and the backend http://mysite/sysadmin wouldn’t load with an Apache error 500-Internal Server error. So I put them back in but I still get Error 404-Unable to resolve the request “sysadmin/index”.

Then, if I try to load http://mysite/backend I get Error 404-Unable to resolve the request "mpl/backend.php". "mpl" is the folder within my hosting account where the site DNS resolves to (as I have other domains in the same account, each pointing to its own folder).

However, if I go to http://mysite/backend.php then it works: the backend login page is loaded and after authentication I get the backend home page.

As you said, there are no any url rules in the backend or base config files. I also added the user component in the base config file with ‘loginUrl’=>array(‘site/login’) as suggested and actionLogin and actionLogout were already in both SiteControllers, with no changes from the default.

As I keep trying it looks more and more like an Apache rewrite problem instead of a Yii problem. Any more ideas? Thanks again.

Maybe you can create a "lite" application which can reproduce all problems you get and post it here (so I can test it)?


Thanks so much for your help. As you may know, Yii 1.1.1 has been released. Since my project is at such an early stage I’ll go ahead and redo it with the new version; perhaps the improvements will help me out. I will use your sugggested backend/frontend structure from the beginning instead of as an afterthought so I’ll come back in a couple of days to report any further problems with the scheme. Thanks again.


Well, I restarted the proyect using Yii 1.1.1 and applying the cookbook frontend/backend article technique; things were going smoothly until I rendered the home page. No layout was rendered!

Upon further investigation I found out that Yii 1.1.1 changed Controller.php to hardcode the layout property to ‘application.views.layouts.column1’. In addition, layouts/column1.php then hardcodes the layout using $this->beginContent(‘application.views.layouts.main’). The backend was not affected because its controller extends from CController, unlike SiteController which is extended from Controller.

Now I’d like to simplify all of this to use the same layout front and back, so I tried doing this “public $layout=‘application.views.’.Yii::App()->endName.‘layouts.column1’;” in Controller.php but keep getting a “Parse error: syntax error, unexpected ‘.’, expecting ‘,’ or ‘;’ in…”.

I don’t know enough yet about PHP or Yii to fix this, so perhaps you could take a look at the cookbook article and update it for Yii 1.1.1. Thanks for your help.

You can’t use string concatenation when defining class fields. Instead, you can set layout in controller’s init() method. The article doesn’t cover such details (I don’t think it needs to), but I’ll take a look at the new Yii app generated by yiic.

Hi again:

I ended up overriding $layout in SiteController (frontend) and BackEndController, both of which are now extended from Controller. I also hardcoded the layout path ‘application.views.(front/back).layouts.(whatever)’ in the layout files. It’s not an elegant solution but it works so I can continue development until I learn a better way to handle this. Let’s see what happens…

Why not just use $this->layout = ‘whatever’; ? Yii will try to find a layout in the views/<endName>/layouts directory.

That did the trick, thank you!

In Controller.php I added this:

public $layout='application.views.layouts.column1';	

public function init()	// override layout for front/back ends



	switch (Yii::App()->endName)


		case 'front':



		case 'back':







And in the layouts I changed the hard coded reference to <?php $this->beginContent();?>.

Well, the problem is solved for now. Next I’ll continue with model creation under 1.1.1 to see what happens. Thank you for your assistance.

I mean:

public $layout = 'column1';

should work, not?


I am looking for help from experts after spending quite some time on this, the front/back is setup and working as expected except setting the public




in controller. If this property is set then the menu is not shown & also the CSS ( because main is not included either i guess) but when this line is commented I see the blue menu, Why this property is not working

It is worked now, I dont know what was done wrong could be the below line in column2.php had back.layouts.main

should be


Thanks for looking into it, regards