Skip to content

Instantly share code, notes, and snippets.

@n1215
Last active August 29, 2015 14:07
Show Gist options
  • Save n1215/640897eeacde100a6f74 to your computer and use it in GitHub Desktop.
Save n1215/640897eeacde100a6f74 to your computer and use it in GitHub Desktop.
【baserCMS】 ユーザーエージェントに応じて適用するテーマを変えるテスト
<?php
/**
* app/Controller/AppController.php
*/
App::uses('BcAppController', 'Controller');
App::uses('BcAgent', 'Lib');
class AppController extends BcAppController {
/**
* テーマをセットする
*
* @return void
*/
public function setTheme() {
parent::setTheme();
$themes = Configure::read('MyConfig.themes');
$agent = BcAgent::findCurrent();
if (empty($agent) || !array_key_exists($agent->name, $themes)) {
return;
}
$this->theme = $themes[$agent->name];
}
}
<?php
/**
* app/Config/setting.php
*/
$config['MyConfig'] = array(
'themes' => array(
'mobile' => 'm-single',
'smartphone' => 'skelton'
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment