Php/zend framework/モバイル版作成
提供: 初心者エンジニアの簡易メモ
PCとMobileをModuleで切り分けて作成する方法
index.php
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/../modules/ZendFramework/library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
require_once 'Net/UserAgent/Mobile.php';
// モバイル判定
$agent = Net_UserAgent_Mobile::singleton();
if (!$agent->isNonMobile()) {
$terminal = 'mobile';
} else {
$terminal = 'default';
}
// router ini add
$router = new Zend_Config_Ini(
APPLICATION_PATH . '/configs/router.ini',
$terminal
);
$router = $router->toArray();
$options = $application->getOptions();
$options['resources']['router']['routes'] = $router['routes'];
$application->setOptions($options);
$application->bootstrap()
->run();
configs/router.ini
[default] routes.api.route = "sample/:action" routes.api.defaults.module = "default" routes.api.defaults.controller = "sample" [mobile] routes.play.route = "sample/:action" routes.play.defaults.module = "mobile" routes.play.defaults.controller = "sample"
