Working with Static Pages

In controller


public function actions()

	{

		return array(

			'page'=>array(

				'class'=>'CViewAction',

			),

		);

	}

In config/main.php




return array(

	'theme'=>'Elysian',


'urlManager'=>array(

			'urlFormat'=>'path',

			'rules'=>array(

				'<controller:\w+>/<id:\d+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

				'site/detail/refno'=>'<controller>/<action>',

			),

		),

I have created view whose path is \mysite\themes\Elysian\views\site\pages\AboutUs\companyprofile.php

When I access localhost/mysite/index.php/site/page&view=AboutUs.companyprofile or using lowercase aboutus I get Error 404

Dear friend,

I hope this helps.

Add the following (may be the first rule).




'<controller:\w+>/page/<view:\w+>'=>'<controller>/page',



this should do it


'site/AboutUs/companyprofile'=>'<controller>/page'

not working

I’m creating many folders inside the pages folder

If I put a view file inside pages folder and access localhost/mysite/index.php/site/page/companyprofile then this works.

But if I put companyprofile.php in pages/aboutus folder then localhost/mysite/index.php/site/page/aboutus.companyprofile is showing Error 404. How can I access different views in different subfolders inside the pages folder ?

you are url is wrong try this in your browser works for me

localhost/mysite/index.php/site/page/aboutus/companyprofile

shows Error 404

Dear Friend,

The following is working for me. Kindly check at your local host and improve my response.

I have 2 files as static pages.I have changed them according to your scenario.

  1. views/site/pages/aboutUs/about.php

  2. views/site/pages/company/index.php

These are the modifications in SiteController.php




public function actions()

	{

		return array(

			// captcha action renders the CAPTCHA image displayed on the contact page

			'captcha'=>array(

				'class'=>'CCaptchaAction',

				'backColor'=>0xFFFFFF,

			),

			// page action renders "static" pages stored under 'protected/views/site/pages'

			// They can be accessed via: index.php?r=site/page&view=FileName

			'page'=>array(

				'class'=>'CViewAction',

				'basePath'=>'pages/aboutUs'

			),

			'company'=>array(

				'class'=>'CViewAction',

				'basePath'=>'pages/company'

			),

		);

	}



This is the configuration for ‘urlManager’ in main.php




'urlManager'=>array(

			'urlFormat'=>'path',

			'showScriptName'=>true,

			'rules'=>array(

			   

				'<controller:\w+>s'=>'<controller>/index',	

				'<controller:\w+>/<action:page||company>/<view:\w+>'=>'<controller>/<action>',		

				'<controller:\w+>/<id:\d+>/<title:\w+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>/*'=>'<controller>/<action>',

			

			),



The following ‘URLs’ are working for me.




//Displays the about.php

http://localhost/blog/index.php/site/page/about


//Displays the index.php

http://localhost/blog/index.php/site/company



The idea here is to modify default base path , while declaring CviewActions.

I have tried creating view files in site/landlords folder.

In config/main.php

‘<controller:\w+>/landlords/<action:\w+>’=>’<controller>/<action>’,

Is this rule correct ?

In SiteController.php I have actionRent() method

when I access rent.php file using localhost/mysite/index.php/site/landlords/rent I get error SiteController cannot find the requested view "rent".

Thanks a lot. That worked. Actually I have created several folders inside the pages folder so I have modified your rule with this

‘<controller:\w+>/<action:\w+>/<view:\w+>’=>’<controller>/<action>’, to take any action name.

and in controller I created


'aboutus'=>array(

				'class'=>'CViewAction',

				'basePath'=>'pages/aboutus',

			),

Now I can access the view file inside the aboutus folder using localhost/mysite/index.php/site/aboutus/companyprofile

Do I need to create action array like this for every subfolder in the pages folder ?

I’m trying to make these 2 links work


http://localhost/mysite/index.php/site/landlords/rent

http://localhost/mysite/index.php/site/landlords/buy

but getting Error 404 The system is unable to find the requested action "landlords". I have actionRent() and actionBuy() in the SiteController

I have created this rule for pages in this folder site/landlords

‘<controller:\w+>/landlords/<view:\w+>’=>’<controller>/<action>’,

and for static pages in the subfolders of the pages folder

<controller:\w+>/<action:\w+>/<view:\w+>’=>’<controller>/<action>’,

Thanks Shaani,

Your suggestion is working for me as well.

This is fine for every subfolders.




'<controller:\w+>/<action:\w+>/<view:\w+>'=>'<controller>/<action>',



It violates the following rule.




'<controller:\w+>/<action:\w+>/<id:\d+>/*'=>'<controller>/<action>',



To make the following URLs work, I am having only 2 options.




http://localhost/mysite/index.php/site/landlords/rent

http://localhost/mysite/index.php/site/landlords/buy



1. Make landlords as action. Put the rent.php and buy.php inside the landlords folder as view files.

2. Make rent and buy as actions. Create the folders rent and buy and put them inside the landlords folder. Create index.php in each folder.

You have to make "sites/landlords"as default path. In this option, "landlords" will disappear from URL.

The following are my inferences on the basics of URL management.

1. In every URL ,every controllerId should be followed by actionId except for default actions.

2. For CViewActions, there should be folder with action name in sites folder or its subfolders.

Expecting some inputs…