在cakepp中制作友谊系统时,我在我的朋友控制器中遇到了类似这样的错误---->
语法错误,意外的";"
请有人来解决这个问题。。。。这是我的友谊控制器代码:
<?php
App::uses('AppController', 'Controller');
/**
* Posts Controller
*
* @property Post $Post
* @property PaginatorComponent $Paginator
*/
class FriendsController extends AppController
{
/**
* Components
*
* @var array
*/
var $layout=null;
public $components = array('Paginator');
function index()
{
}
function friendlist($user_id)
{
$session_user_id = $this->Session->read('Auth.User.id');
if($user_id == $session_user_id )
{
$user_to = $session_user_id ;
}
else
{
$user_to = $user_id;
}
$this->Friend->find('all',array('Friend.user_to'=>$user_to,'Friend.status'=>'Accepted');
}
function add_friend ( $id )
{
if(!empty($this->data))
{
$this->Friend->Create();
if($this->Friend->save($this->data))
{
$this->Session->setFlash('Friendship Requested');
$this->redirect(array('controller'=>'users','action'=>'login'));
}
}
if(empty($this->data))
{
$this->set('friends', $this->Friend->find('all',array('Friend.id'=>$id));
}
}
function accept_friendship ( $id )
{
$this->Friend->id = $id;
$current_status = $this->Friend->field('status');
if($current_status=='Requested') {
$this->Application->saveField('status', 'Accepted');
}
$this->Session->setFlash('Friendship Accepted');
$this->redirect(array('controller'=>'friends','action'=>'index'));
}
}
语法错误。在第36行和第52行。您忘记添加右括号
更改的代码
$this->Friend->find('all',array('Friend.user_to'=>$user_to,'Friend.status'=>'Accepted');
至
$this->Friend->find('all',array('Friend.user_to'=>$user_to,'Friend.status'=>'Accepted'));
来自
$this->set('friends', $this->Friend->find('all',array('Friend.id'=>$id));
至
$this->set('friends', $this->Friend->find('all',array('Friend.id'=>$id)));
只是语法有问题,您忘记了在查找和设置语法中关闭括号
添加以下代码并尝试:
$this->Friend->find('all',array('Friend.user_to'=>$user_to,'Friend.status'=>'Accepted'));
和
$this->set('friends', $this->Friend->find('all',array('Friend.id'=>$id)));
我的建议是,请使用一些不错的一个编辑器,它可以帮助你解决语法错误,就像我使用的是netbeans及其最佳版本一样。