G
G
Greg Popov2015-04-23 11:29:31
Yii
Greg Popov, 2015-04-23 11:29:31

How to use templates and subdomains together in Yii?

Hello. There was an idea to use two templates: one for the desktop, the second for portable devices.
Now the essence of the question: how, having created two topics, to display them as, for example, done in VK: vk.com m.vk.com and where to redirect to one or another part of the application?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sasha, 2015-04-23
@madmages

there is a suspicion that USER-AGENT is being dismantled in search of mobility. This is what the function in chrome "encrypt as if I'm from a computer" is built on.

H
Helmut, 2015-04-23
Konig @helmut_kenig

Try to create a subdomain, make a common database, upload all media files and user files to a separate server or subdomain and redirect index.php to the mobile version.

<?php

$iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$android = strpos($_SERVER['HTTP_USER_AGENT'],"Android");
$palmpre = strpos($_SERVER['HTTP_USER_AGENT'],"webOS");
$berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod");
$mobile = strpos($_SERVER['HTTP_USER_AGENT'],"Mobile");
$symb = strpos($_SERVER['HTTP_USER_AGENT'],"Symbian");
$operam = strpos($_SERVER['HTTP_USER_AGENT'],"Opera M");
$htc = strpos($_SERVER['HTTP_USER_AGENT'],"HTC_");
$fennec = strpos($_SERVER['HTTP_USER_AGENT'],"Fennec/");
$winphone = strpos($_SERVER['HTTP_USER_AGENT'],"WindowsPhone");
$wp7 = strpos($_SERVER['HTTP_USER_AGENT'],"WP7");
$wp8 = strpos($_SERVER['HTTP_USER_AGENT'],"WP8");
if ($ipad || $iphone || $android || $palmpre || $ipod || $berry || $mobile || $symb || $operam || $htc || $fennec || $winphone || $wp7 || $wp8 === true) {
    header('Location: http://m.site.com'); 
}

?>

The code for the index file, you already have <?php ?> in the code, so just remove them and put them in this one. so that there is no error

A
alex stephen, 2015-04-23
@berezuev

You can add a rule to urlManager

'rules' => [
     'http://m.vk.com/<action:(.+)>' => '/<action>/?mobile=1',
]

and in view layouts, if this parameter is present, return the mobile template

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question