위시리스트를 생성하려고합니다.데이터 저장에 문제가있는 CakePHP (HABTM)
사용자 및 제품 모델이 있습니다. 사용자에게 희망 목록이 있습니다. 위시리스트에는 많은 제품이 있습니다. 가
나는 사용자가 위시리스트를 가지고 위시리스트 그래서 난 wish_lists 같은 URL을 가질 수 있습니다 제품을 가지고 그것을 만드는 중이라서 이유는 추가/
은/:user_id
을
나는 테이블이
id
와
wish_lists
라고 만든
을 PRODUCT_ID하고,
name
.
wish_list_id
및 product_id
으로 products_wish_lists
이라는 테이블을 만들었습니다.
class WishListsController extends AppController
{
var $hasOne = 'User';
var $hasMany = 'Product';
function beforeFilter()
{
parent::beforeFilter();
$this->Auth->deny('add');
}
function add($id)
{
$user = $this->Session->read("Auth.User");
$this->WishList->set(array(
'User.id' => $user['id'],
'Product.id'=>$id,
'WishList.name'=>'default'
));
if($this->WishList->save())
{
$this->Session->setFlash('This product has been added to your wishlist.', 'flash_good');
}
else
{
$this->Session->setFlash('Error: This product was not added to your wishlist.', 'flash_bad');
}
$this->redirect(array("controller"=>"products","action"=>"view",$id));
}
}
내가 localhost/wish_lists/add/1
에 갈 때 그것은 저장 한 매번 저에게 말한다 : 나는 여기에서
은 위시리스트 컨트롤러입니다. 그러나 데이터는 데이터베이스에 추가되지 않습니다.
내가 뭘 잘못하고 있는지 확실하지 않은가요?