Yii Framework Forum: andy_s, need help with front/backend setup - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

andy_s, need help with front/backend setup Rate Topic: -----

#1 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 476
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 13 March 2010 - 04:10 AM

Hi:

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.
José
0

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 13 March 2010 - 05:06 AM

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

#3 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 476
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 13 March 2010 - 06:11 AM

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.
José
0

#4 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 13 March 2010 - 06:50 AM

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...
0

#5 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 476
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 13 March 2010 - 02:00 PM

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 (GoDaddy.com) 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.
José
0

#6 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 13 March 2010 - 02:45 PM

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

#7 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 476
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 14 March 2010 - 03:29 AM

Andy:

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.

Regards,
José
0

#8 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 476
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 15 March 2010 - 02:21 PM

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.
José
0

#9 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 15 March 2010 - 03:24 PM

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.
0

#10 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 476
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 16 March 2010 - 12:37 PM

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...
José
0

#11 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 16 March 2010 - 12:46 PM

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

#12 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 476
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 16 March 2010 - 01:36 PM

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
{
	parent::init();
	switch (Yii::App()->endName)
	{
		case 'front':
			$this->layout='application.views.front.layouts.column1';	
			break;
		case 'back':
			$this->layout='application.views.back.layouts.column1';	
			break;
		default:
			break;
	}
}


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.
José
0

#13 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 16 March 2010 - 02:34 PM

I mean:

public $layout = 'column1';


should work, not?
0

#14 User is offline   sltech 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 12-April 11

Posted 10 December 2011 - 05:30 PM

Hi,

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

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

OR
$layout='column1'; 


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
0

#15 User is offline   sltech 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 12-April 11

Posted 10 December 2011 - 05:38 PM

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
$this->beginContent('application.views.back.layouts.main');


Thanks for looking into it, regards
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users