두 번째 테이블에서 데이터를 추가하는 함수를 호출 할 때 하나의 컨트롤러 파일에서 두 테이블의 데이터를 추가하고 싶습니다. 오류가 발생했습니다. 오류 : 멤버 함수 호출 개체가 아닌 여기에CakePhp에서 하나의 컨트롤러 파일을 사용하여 두 테이블에 데이터를 삽입하고 싶습니다.
()를 저장하는 VAR을 $ = 배열 ('메인 모델 이름', '2 차 모델 이름을'사용
<?php
class CountryController extends AppController {
var $name = 'Country';
var $helpers = array('Html', 'Form');
// called index function
public function index() {
$this->render();
}
// Function for add countries in database
public function addCountry() {
if (empty($this->data)) {
$this->render();
} else {
// $this->cleanUpFields();
if ($this->Country->save($this->data)) {
$this->Session->setFlash('The Counrty has been saved');
$this->redirect('/country/index');
} else {
$this->Session->setFlash('Please correct errors below.');
}
}
}
public function addCity() {
$cities = $this->set('country', $this->Country->find('all'));
$this->set(compact('cities'));
if(empty($this->data)){
$this->render();
} else {
print_r($this->data);// die();
if ($this->City->save($this->data)) {
$this->Session->setFlash('The City has been saved');
$this->redirect('/country/index');
} else {
$this->Session->setFlash('Please correct errors below.');
}
}
}
}
?>
답장을 보내 주셔서 감사합니다. .. 시도해보고 모델 파일 이름 city.php를 만들고 db라는 도시에 테이블을 만듭니다.하지만 이번에는 오류가 발생합니다. Notice (8) : 문자열을 문자열로 변환하는 배열 [CORE /Cake/Model/Datasource/DboSource.php, line 459] –
입력 값을 확인하십시오. – Elby
나중에 작동합니다 .. 이제 자신의 맞춤 함수로 시도했습니다 .. 이제 save() 작업을 시도합니다 ... 감사합니다 ..! cakePHp에서 db에 대한 사용자 정의 쿼리를 작성할 수있는 곳을 알려주십시오. –