我有简单的关系表:每个表(协议)“ umowas”都有一个表(成人)“ rodzics”项,一个有表(儿童)“ dziecis”项。
当调用myaddress.com/cakephp/Umowas/add时,我看不到带有项目名称的项目“ rodzic_id”和“ dzieci_id”的下拉菜单。我只看到数字。
例如,“ rodzic_id”的下拉菜单显示Array(1 => 1,2 => 2,3 => 3),而不是其记录的名称,例如array(1 =>'Item name 1',2 =>'项目名称2').....
Debug.log和Error.log为空。
我在屏幕底部的查询是:
Nr Query Error Affected Num. rows Took (ms) 1 SELECT
Rodzic .
id FROM
akademia-uat .
rodzics AS
Rodzic WHERE 1 = 1 2 2 3 2 SELECT
Dzieci .
id FROM
akademia-uat .
dziecis AS
Dzieci WHERE 1 = 1 1 1 2
我的代码是:
<?php
class UmowasController extends AppController {
var $name = 'Umowas';
var $scaffold;
var $helpers = array('Form' );
function index() {
$this->Umowa->recursive = 1;
$umowas = $this->Umowa->find('all');
$this->set('umowas', $umowas);
}
}
?>
-----------------------------------------
<?php
class RodzicsController extends AppController {
var $name = 'Rodzics';
var $scaffold;
function index() {
$this->Rodzic->recursive = 1;
$rodzics = $this->Rodzic->find('all');
$this->set('rodzics', $rodzics);
}
}
-------------------------------------------------------
<?php
class DziecisController extends AppController {
var $name = 'Dziecis';
var $scaffold;
function index() {
$this->Dzieci->recursive = 1;
$dziecis = $this->Dzieci->find('all');
$this->set('dziecis', $dziecis);
}
}
------------------------------------------
<?php
class Umowa extends AppModel {
var $name = 'Umowa';
public $belongsTo = array(
'Rodzic' => array(
'className' => 'Rodzic',
'conditions' => '',
'order' => '',
'foreignKey' => 'rodzic_id' //or your external key
),
'Dzieci' => array(
'className' => 'Dzieci',
'conditions' => '',
'order' => '',
'foreignKey' => 'dzieci_id' //or your external key
)
);
var $helpers = array('Form' );
function add() {
if (!empty($this->data)) {
$this->Umowa->create();
$this->Umowa->save($this->data);
$this->redirect(array('action'=>'index'));
}
$rodzics = $this->Umowa->Rodzic->generateList();
$this->set('rodzics', $rodzics);
$dziecis = $this->Umowa->Dzieci->generateList();
$this->set('dziecis', $dziecis);
}
}
?>
--------------------------------------------------------
<?php
class Rodzic extends AppModel
{
var $name = 'Rodzic';
var $hasMany = 'Umowa';
}
?>
-------------------------------------------------------
<?php
class Dzieci extends AppModel
{
var $name = 'Dzieci';
var $hasMany = 'Umowa';
}
?>
---------------------------------------------------------
view/Rodzics/add and do not exists
view/Umowas/add do not exists
view/Dziecis/add do not exist
`
我的表是这样的:
`
CREATE TABLE IF NOT EXISTS `dziecis` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`imie_dziecka` varchar(18) DEFAULT NULL,
`nazwisko_dziecka` varchar(15) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
CREATE TABLE IF NOT EXISTS `rodzics` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`imie_rodzica` varchar(18) DEFAULT NULL,
`nazwisko_rodzica` varchar(15) DEFAULT NULL,
`telefon` int(9) DEFAULT NULL,
`adres_email` varchar(50) DEFAULT NULL,
`ulica` varchar(30) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
CREATE TABLE IF NOT EXISTS `umowas` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`warunek_umowy` varchar(2048) DEFAULT NULL,
`data_rozwiazania_warunku` date DEFAULT NULL,
`data_zawarcia_umowy` date DEFAULT NULL,
`data_zerwania_umowy` date DEFAULT NULL,
`nr_umowy` int(4) DEFAULT NULL,
`rok_szkolny` int(4) DEFAULT NULL,
`wizerunek` varchar(3) DEFAULT NULL,
`miesiac_rozpoczecia_platnosci` int(2) DEFAULT NULL,
`raty` varchar(3) NOT NULL,
`utworzono` date NOT NULL,
`modyfikacja` date NOT NULL,
`zabezpieczona` varchar(3) NOT NULL,
`wydrukowana` varchar(3) NOT NULL,
`dzieci_id` int(11) NOT NULL,
`rodzic_id` int(11) NOT NULL,
`product_id` int(11) NOT NULL,
`status_umowy_id` int(11) NOT NULL,
`miasto_id` int(11) NOT NULL,
`klasa_lub_grupa_dziecka_id` int(11) NOT NULL,
`cennik_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
最佳答案
我已将项目中的所有表格和名称翻译成英语。通过命令行蛋糕烘烤也完成了工作,所有表开始工作并显示字段。问题出在模型中,没有声明为公共$ displayField。
每个人每天都要做脚手架命令行工具并有英文名字,这很容易。而且,大多数importand是声明$ displayField并将其指向每个表中的title或name字段。
谢谢大家的支持。