Submodule as Subdomain

Hi there,

I am currently developing an MultiStore E-commerce project. I have a module Stores, and its submodules are the store names. So for example, I want to visit the store Sample1, in my URL I will have http://mysampleproject.com/stores/sample1, Sample2 will be http://mysampleproject/stores/sample2, and so on.

What should I do so that each stores can be accessed as a subdomain, such as http://sample1.mysampleproject.com? Can this be done via urlManager? Or is there a better way to handle my stores?

Hi there,

You may want to use "Parameterizing Hostnames" and see if that works for you

maybe this link help you click this link and navigate to pointing to subdomain sub topic http://suriyanphp.blogspot.in/2012/07/using-modules-in-yii.html

Have the very same thing :)

In config I set:


'onBeginRequest' => array('DomainManager', 'route'),

where that class adds url rules according to domains:


/**

 * Manage domains and subdomains

 */

class DomainManager

{

	public static function route()

	{

		//check if domain is valid/active and set it to Yii::app()->params['store_domain'] + some other things like preloaded store AR

		...

		//add url rules with domain names

		$urls = array(

			// your main site domain from config

			'http://' . Yii::app()->params['root_domain'] . '/<controller:\w+>/<id:\d+>'=>'root/<controller>/view',

			// store domain/subdomain

			'http://' . Yii::app()->params['store_domain'] . '/<controller:\w+>/<id:\d+>'=>'shop/<controller>/view',

			// all other rules

			...

		);


		Yii::app()->getUrlManager()->addRules($urls);

	}

}



This is a bit simplified but I hope you get the concept.

Thanks to all your answers. All the suggested solutions refers to one thing: Parameterizing Hostnames. I was on that page yesterday and I’m positive that I’ve read the whole page…not sure how I missed that one. Anyway, thanks again. +1 to you all.