我创建了一个用户配置文件,用户可以在其中添加他们的信息。所以在URL部分,我希望他们把他们的其他链接,如Facebook,www.facebook.com/user等CakePHP关联错误?不会保存关联的表
但是,当我点击保存没有更新?
下面是用户的型号: 型号/ user.php的
<?php
class User extends AppModel {
public $name = 'User';
public $hasMany = array (
'UserWeb'=>array(
'className'=>'UserWeb',
'foreignKey'=>'user_id'
)
);
}
?>
为UserWeb模型: 型号/ UserWeb.php
<?php
class UserWeb extends AppModel {
public $name = 'UserWeb';
public $belongsTo = array('User' =>
array('className' => 'User',
'conditions' => '',
'order' => '',
'foreignKey' => 'user_id'
)
);
}
?>
用户控制器:
$this->User->id = $this->Auth->user('id');
if ($this->request->is('post')) {
if ($this->User->save($this->request->data, array('validate' => false))) {
$this->Session->setFlash('Profile updated succsessefully!',
'default', array('class' => 'okmsg'));
$this->redirect($this->request->here);
} else {
$this->Session->setFlash('Profile could not be saved. Please, try again.',
'default', array('class' => 'errormsg'));
}
}
与查看表单:
<?php
echo $this->Form->create();
echo $this->Form->input('UserWeb.title',
array('label'=>false,'placeholder'=>'Title'));
echo $this->Form->input('UserWeb.url',
array('label'=>false,'placeholder'=>'Enter URL'));
echo $this->Form->end('Save');
?>
任何人都可以帮忙吗?我正在努力寻找很多时间的解决方案。 当我提交表单时,它不会在user_webs表中存储新信息。
而且顺便说一句这里是表:
CREATE TABLE `user_webs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT '0',
`title` varchar(128) DEFAULT NULL,
`url` varchar(128) DEFAULT NULL,
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `web` (`user_id`),
CONSTRAINT `web` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8