100分求解:cakephp的controllers问题

shyming 2010-09-18 09:53:50
为什么controllers里的函数不能被调用啊,郁闷,有没有用过的大虾指导一下。本人刚学这个。十分感谢!在线等。


具体情况是:
首先,访问http://localhost,显示login界面
然后,在login界面输入用户名密码提交Form,出现以下错误:
无法显示网页,可能是网络问题或404错误!
您可以尝试刷新此链接:
http://localhost/clients/auth

没有道理的啊,是不是设置有问题?按照cakephp文档上讲应该是可以访问/clients/auth的。
具体的可以参考:http://book.cakephp.org/cn/view/977/Controller-Methods

1. C:\Apache2\htdocs\app\config\routes.php
Router::connect('/', array('controller' => 'clients', 'action' => 'login'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

2. C:\Apache2\htdocs\app\views\clients\login.ctp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<form action="/clients/auth" method="post">
<table>
<tr>
<td><label>用户名:</label><input type="text" name="data[username]"/></td>
</tr>
<tr>
<td><label>密码:</label><input type="password" name="data[passwd]"/></td>
</tr>
<tr>
<td> </td>
<td><button type="submit">登 录</button></td>
</tr>
</table>
</form>
</body>
</html>

3. C:\Apache2\htdocs\app\controllers\clients_controller.php
<?php
class ClientsController extends AppController {

var $name = 'Clients';

var $uses = array();


function index() {
$this->render('/clients/login');
}

function login() {
$this->render('/clients/login');
}

function logout() {
$this->Session->destory();
}

function auth() {
$username = $this->data['username'];
$passwd = $this->data['passwd'];
$this->loadModel('Client');
$client = $this->Client->find('first', array('conditions' => array('username'=>$username)));

if(empty($client['Client']['uid'])) {
$this->render('/clients/login');
} else {
$this->loadModel('User');
$user = $this->User->find('first', array('conditions' => array('uid'=>$client['Client']['uid'], 'passwd'=>md5($passwd))));
// 如果无法找到该用户,则跳转至
if(empty($user)) $this->render('/clients/login');
else {
$full_name = $user['User']['fname']." ".$user['User']['lname'];
$this->Session->write('uid',$user['User']['uid']);
$this->Session->write('mid',$client['Client']['mid']);
$this->Session->write('email',$user['User']['email']);
$this->Session->write('nickname',$full_name);

$this->redirect(array('controller' => 'books', 'action' => 'pending'));
}

}

}


function beforeFilter() {
echo "test beforeFilter";
$this->auth;

}

function beforeRender() {
echo "test beforeRender";
$this->auth;

}

function afterFilter() {
echo "test afterFilter";
$this->auth;

}

}
?>

有愿意讨论的欢迎加我QQ:30490031.
...全文
132 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
shyming 2010-09-26
  • 打赏
  • 举报
回复
问题已经解决!apache配置问题。
shyming 2010-09-19
  • 打赏
  • 举报
回复
我想beforefilt()是先被执行的,其顺序甚至早于login,因为在clients里调用了controller就触发了beforefilt()。。。。可以不用理beforefilt(),因为这只是我用来试试的,忽略好了。

问题在于auth方法找不到。显示页面不存在。。。。
hero1010 2010-09-19
  • 打赏
  • 举报
回复
怎么会跳到beforefilt里面,你不是提交到auth方法里面么
  • 打赏
  • 举报
回复
没用过cakephp,PHP代码被cakephp解析一次后再被php.exe解析。

路过帮顶~
shyming 2010-09-18
  • 打赏
  • 举报
回复
自己顶一下!
附带说明下,beforeFilter()等三个函数是我加进试试的,可以显示test beforeFilter字样,但是也有Notice (8): Undefined property: ClientsController::$auth [APP\controllers\clients_controller.php, line 51]错误,这个倒没关系。

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧