这是我的控制器代码
<?php
public function view(){
$this->loadModel('User');
$this->loadModel('Claim');
$this->Claim->unbindModel(
array('belongsTo' => array('User',"Category"),
'hasMany' => array('Response')));
$user= $this->User->findById($this->params['id']);
$claim=$this->Claim->find('all', array(
'conditions' => array('user_id' => $user['User']['id']),
'fields' => array('title','id','support_count','oppose_count','description','category_id')));
if(isset($user['User'])):
$this->set('User',$user);
else:
$this->Session->setFlash('User Not Found!', 'flash',array('alert'=>'error'));
$this->redirect('/');
endif;
}?>
这是我的模型代码
class User extends AppModel {
public $name = 'User';
public $validate = array(
'handle' => array(
'alphaNumeric' => array(
'rule' => 'alphaNumeric',
'required' => true,
'message' => 'Invalid Username'
),
'between' => array(
'rule' => array('between', 5, 15),
'message' => 'Username should be between 5 to 15 characters'
)),
'password' => array(
'rule' => array('between', 5, 15),
'message' => 'Password should be between 5 to 15 characters',
'last' => true,
'required' => true
),
'email' => array(
'email' => array(
'rule' => 'email',
'required' => true,
'message' => 'Enter valid email address'
)
)
); }
这是查看代码
<?php echo $this->Html->link($Claim['Claim']['title'],
array('Controller'=>'User','action'=>'view')); ?>
我收到此错误“未定义变量:Claim [APP/View/User/view.ctp,第 6 行]”我试图在模型中将“claim”定义为 public $name = 'Claim'; 但它不起作用我试图将它定义为 $this->set($claim('Claim')); 但我仍然遇到同样的错误......我需要一些帮助,谁能帮我解决这个问题