gpt4 book ai didi

cakephp 和创建一个移动站点

转载 作者:行者123 更新时间:2023-12-04 05:28:41 25 4
gpt4 key购买 nike

我已经创建了我的 cakephp 网站,现在想创建它的移动版本。我已关注此处和其他页面上有关创建移动网站的问题。但是,在实现代码后,页面不会加载,只显示一个没有标题等的空白页面。

这是我的 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>&nbsp;</td>

<td>&nbsp;</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

最佳答案

使用 CakePHPs 主题功能 ( http://book.cakephp.org/2.0/en/views/themes.html ) 不是更干净吗?

我过去做过类似的事情,你在 before 过滤器回调中检测请求是否是移动的,如果是,那么只需切换到移动主题。

关于cakephp 和创建一个移动站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12893190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com