Yii Framework Forum: Multisite - Yii Framework Forum

Jump to content

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

Multisite Rate Topic: -----

#1 User is offline   gkeb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 15-February 10

Posted 15 February 2010 - 02:57 PM

Witam. To mój pierwszy post tutaj.
Niedawno wpadłem na ten framework i pomyślałem, że może warto się nim zainteresować. Początkowe przykłady wydają się dość ciekawe. To tyle tytułem wstępu :)

Zastanawiam się nad czymś takim. Istnieją przykładowo takie domeny:
www.domena.pl
forum.domena.pl
blog.domena.pl
...
Czy da się to tak zrobić by to działało na jednej instalacji Yii. Na przykładowym serwerze katalogi są takie:
/domains/domena.pl/public_html
/domains/domena.pl/public_html/forum
/domains/domena.pl/public_html/blog

Macie propozycje jak to wykonać? Forum i blog to miałyby być oddzielne aplikacje ale mające część wspólną (np. baza userów).
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 15 February 2010 - 03:10 PM

Hi, with help of modules you can do it.

The directory structure could look like this:

- /domains/domena.pl/public_html
  - protected
    - controllers
    - models
    - views
    - modules
      - blog
        - controllers
        - views
      - forum
        - controllers
        - views


In config you can manage all possible url rules:

'components' => array(
   ...
   'urlManager' => array(
      'rules' => array(

         'http://www.domena.pl' => 'site/index',
         'http://www.domena.pl/contact' => 'site/contact',
         ...

         'http://blog.domena.pl' => 'blog/site/index',
         ...

         'http://forum.domena.pl' => 'forum/site/index',        
         ...

      ),
   ),
   ...
),


Also take a look at these cookbooks: #1, #2

Sorry for english, i translated your post with google :)
0

#3 User is offline   gkeb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 15-February 10

Posted 15 February 2010 - 04:24 PM

Thanks very much :) I must redirect all subdomain to index.php in .htaccess?
0

#4 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 15 February 2010 - 04:33 PM

Well, I guess you run everything under the same ip address. So in the .htaccess you must only make sure every request gets redirected to the index.php entry-script.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

0

#5 User is offline   kapi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 12-March 10
  • Location:Poland

Posted 15 March 2010 - 04:12 AM

Hi,

I had similar problem.

My application has few modules and base part with components, extensions and models for all modules.

My application handle domain in index.php.

Its not too pretty solution but I want load separated config per module and my modules has similar url rules.

My index.php file

$yii=dirname(__FILE__).'/../yii-1.1.0.r1700/yii.php';
defined('YII_DEBUG') or define('YII_DEBUG',true);
require_once($yii);

function getDomainName() {
        $http = ($secure = (isset($_SERVER['HTTPS']) && !strcasecmp($_SERVER['HTTPS'],'on'))) ? 'https' : 'http';
        if (isset($_SERVER['HTTP_HOST'])) {
                $hostInfo=$http.'://'.$_SERVER['HTTP_HOST'];
        } else {
                $hostInfo=$http.'://'.$_SERVER['SERVER_NAME'];
                $port=$_SERVER['SERVER_PORT'];
                if (($port!=80 && !$secure) || ($port!=443 && $secure))
                        $hostInfo.=':'.$port;
        }
        $matches = array();
        preg_match("/^(?<protocol>(http|https):\/\/)(?<www>(www\.|))((?<domain>.+\.[a-z]+))$/", $hostInfo, $matches);
        return trim($matches['domain']);
}

switch (getDomainName()) {
	case 'subdomain1.pl':
		$config = 'subdomain1';
		break;
        default:
                exit;
                break;
}
Yii::createWebApplication(dirname(__FILE__).'/protected/config/'.$config.'.php')->run();



function getDomainName() based on http://www.yiiframew...oc/cookbook/55/

and I have main config file
return array(
	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',	
	'import'=>array(
		'application.models.*',
		'application.components.*',
	),	
	'components'=>array(
		'urlManager'=>array(
			'urlFormat'=>'path',
			'showScriptName'=> false,
		),
	),
	'params'=>array(),
);


and configs for all subdomains (one per subdomain)

$main = include 'main.php';

$hc = array(
	'name'=>'subdomain1',
	'defaultController'=>'index',
	'modules'=>array(
		'subdomain1'=>array(
			'layout'=>'subdomain1',
			'defaultController'=>'index',
		),
	),	
	'components'=>array(
		'urlManager'=>array(
                    .....
		     ),
		),
	),
	'params'=>array(),
);

return CMap::mergeArray($main, $hc);



Modules in my application are not exactly modules but separated application with one common part.
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