내가 마일 모델 (테이블) 사이의 문제 생성의 관계 (외래 키)가, 내가 케이크 설명서를 따라하지만관계 (외래 키) CakePHP의
의 관계를 작동하지 않습니다 마르카 1-N MODELOS
모델 Marca.php
<?php
class Marca extends AppModel
{
var $name = 'Marca';
public $displayField = 'nombre';
var $hasMany = array(
'Modelo' => array(
'className' => 'Modelo',
'foreignKey' => 'marca_id'
)
);
}
?>
모델 Modelo.php
<?php
class Modelo extends AppModel
{
var $name = 'Modelo';
var $belongsTo = array(
'Marca' => array(
'className' => 'Marca',
'foreignKey' => 'marca_id'
)
);
}
?>
ModelosContro 크 로스 오류가 발생
<?php
class ModelosController extends AppController{
var $name = 'Modelos';
var $helpers = array('Html','Form');
//var $scaffold;
function index(){
$modelos = $this->Modelo->find('all',array(
'fields'=>array(
'Modelo.nombre',
'Modelo.valido',
'Modelo.id',
'Modelo.marca_id'),
'order'=>'Modelo.nombre ASC')
);
$this->set('modelos',$modelos);
}
function add(){
if (!empty($this->data)){
$this->Modelo->create();
if ($this->Modelo->save($this->data)){
$this->Session->SetFlash('Modelo Nuevo Creado');
$this->redirect(array('action'=>'index'),null,true);
}else{
$this->Session->SetFlash('No se ha Agregado el Modelo, intente de Nuevo');
}
}
// $this->loadModel('Marca');
$marcas = $this->Modelo->Marca->find('list'); <<-----this is 31 line, where is the error
debug($marcas);
$this->set(compact('marcas'));
}
function edit($id = null){
if (!$id){
$this->Session->SetFlash('Modelo Incorrecto');
$this->redirect(array('action'=>'index'),null,true);
}
if (empty($this->data)){
$this->data = $this->Modelo->find('first',array('conditions'=>array('Modelo.id'=> $id)));
}else{
if ($this->Modelo->save($this->data)) {
$this->Session->SetFlash('El Modelo se ha Guardado');
$this->redirect(array('action'=>'index'),null,true);
}else{
$this->Session->SetFlash('La Modelo No fue Guardado, intente de Nuevo');
}
}
}
}
?>
은 다음과 같습니다
오류 : 비 객체() 멤버 함수 찾기에 파일을 호출 : /var/www/tlfmovil/app/Controller/ModelosController.php
줄 : 31
관계가 올바르게 설정되지 않았기 때문에 오류라고 생각합니다. 제게 도움주세요.
죄송합니다.
영어를 이름 지정에 사용하지 않는 문제는 복수형이 다르게 처리되기 때문에 규칙이 엉망이된다는 것입니다. Marca 모델에서'public $ useTable = 'marcas';'를 설정하십시오. – Nunser
@nuns - 오류는 테이블이 부족할 필요가 없습니다. 연관이 작동하지 않는 무언가가 있기 때문에 모델을 찾지 않아서 발생했습니다. – Dave
'Modelo' 모델이 실제로 사용되고 CakePHP가 'generic'모델을 생성하지 않는지 확인하십시오; 'debug (get_class ($ this-> Modelo)); ' – thaJeztah