我已经创建了我的 cakephp 网站,现在想创建它的移动版本。我在此处和其他页面上关注了有关创建移动网站的问题。但是,在实现代码后,页面不会加载,只会显示一个没有标题等的空白页面。
这是我的应用控制器中的代码
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