Cakephp Web サイトを作成しましたが、モバイル版を作成したいと考えています。モバイル サイトの作成に関するこのページや他のページの質問をフォローしました。ただし、コードを実装した後、ページは読み込まれず、タイトルなどのない空白のページが表示されます。
ここに私のappcontrollerのコードがあります
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array(
'DebugKit.Toolbar',
'Session',
'Auth'=>array(
'loginRedirect'=>array('controller'=>'users', 'action'=>'login'),
'logoutRedirect'=>array('controller'=>'users', 'action'=>'login'),
'invoiceRedirect'=>array('controller'=>'invoices', 'action'=>'viewinvoice'),
'authError'=>"You can't access this page",
'authorize'=>array('Controller')
)
);
public function isAuthorized($user){
return true;
}
public function beforeFilter(){
$this->Auth->allow('index','view');
$this->Auth->allow('about_us','view');
$this->Auth->allow('contact_us','view');
$this->Auth->allow('privacy','view');
$this->Auth->allow('','');
$this->Auth->allow('forgotten_password','view');
if ($this->request->isMobile()){
$this->is_mobile = true;
$this->set('is_mobile', true );
$this->autoRender = true;
}
$this->set('logged_in', $this->Auth->loggedIn());
$this->set('current_user',$this->Auth->user());
}
function afterFilter(){
// if in mobile mode, check for a valid view and use it
if (isset($this->is_mobile) && $this->is_mobile) {
$view_file = file_exists( 'Views' . $this->name . DS . 'mobile/' . $this->action . '.ctp' );
$layout_file = file_exists( 'Layouts' . 'mobile/' . $this->layout . '.ctp' );
if($view_file || $layout_file){
$this->render($this->action, ($layout_file?'mobile/':'').$this->layout, ($view_file?'mobile/':'').$this->action);
}
}
}
public function pdo_error(){
$this->set('title_for_layout', 'Error');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.jpg');
$this->layout='home_layout';
}
}
ここに私のログイン機能があります
public function login(){
//allows users to log in to the website
$this->set('title_for_layout', 'Welcome to eBox: Innovative Invoice System');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.png');
$this->set('comp', 'comp.jpg');
$this->layout='homepage';
//if the information is posted to the database
if ($this->request->is('post')){
//and matches correctly to the database
if ($this->Auth->login()){
//matches the data to the database
$username = $this->request->data['User']['username'];
//get the users User.access_level
$acl= $this->Auth->User('access_level');
switch($acl){
case 1:
//if the access_level=1 redirects user to Eboxs/home_employee
$this->redirect( array('controller' => 'Eboxs','action' => 'home_employee'));
break;
case 2:
//if the access_level=2 redirects user to Eboxs/home_admin
$this->redirect( array('controller' => 'Eboxs','action' => 'home_admin'));
break;
default:
//if the access_level=anything else redirects user to Eboxs/home
$this->redirect( array('controller' => 'Eboxs','action' => 'home'));
break;
}
}
else{
}
}else{
}
}
これが私のmobile.ctpレイアウトです
<?php echo $this->Html->docType('xhtml-trans'); ?>
<html>
<div id = "header" style="background-image:url(<?php echo $this->webroot; ?>img/BannerGradient2.jpg);">
<head>
<title>hi</title>
<?php echo $this->Html->css($stylesheet_used); ?>
<?php echo $this->Html->image($image_used, array(
"alt" => "eBox",
'url' => array('controller' => 'Users', 'action' => 'login'))) ?>
</head>
</div>
<body>
<?php echo $this->Session->flash(); ?>
<?php echo $this->fetch('content'); ?>
</div>
<div id="footer">
<p align= center>
<?php echo $this->Html->link('About Us', array('controller' => 'eboxs', 'action'=>'about_us')) ;?>
|
<?php echo $this->Html->link('Contact Us', array('controller' => 'eboxs', 'action'=>'contact_us')) ;?>
|
<?php echo $this->Html->link('Privacy', array('controller' => 'eboxs', 'action'=>'privacy')) ;?>
</div>
</body>
</html>
ここに私のlogin.ctpファイルがあります
<table id ="loginform">
<?php echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' => 'login')));?>
<td><text6><?php echo "Username"?></text6></td>
<td><?php echo $this->Form->input('username',array('label'=>false,'size'=>7));?></td>
<td> </td>
<td> </td>
<td><text6><?php echo "Password"?></text6></td>
<td><?php echo $this->Form->input('password',array('label'=>false,'size'=>12));?></td>
<td><?php echo $this->Form->end('Login');?></td>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><text6>Forgot your password?</td>
<td><?php echo $this->Html->link('Click Here', array('action'=> 'forgotten_password')) ;?></td>
</tr></text6>
</table>
シンプルなログインページを作成しようとしています。私はcakephp 2.0を使用しています