CakePHP的displayField用法 [英] CakePHP displayField usage
问题描述
你可以帮我如何使用CakePHP的displayField指令,我不知道如何使用它...
can you help me how to use CakePHP's displayField directive, I can not figure out how to use it...
所以,在模型文件中,我有以下代码...
so, in a model file, i have following code...
<?php
class Task extends AppModel {
class Task extends AppModel {
var $name = 'Task';
var $displayField = 'projectName';
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
如何使用它,在选择表单字段中显示fied projectName?
how can i use this, to display fied projectName in select form field?
!!
推荐答案
因此,您拥有 Task belongsTo Project
(FK: project_id)。你想在任务/添加和任务/编辑视图中创建一个项目选择框。
So, you have Task belongsTo Project
(FK: project_id). You want to make a project select box in tasks/add and tasks/edit views.
问题是项目表没有一个字段 name
或 title
所以选择框是空的,如果有一个 name
或 title
字段,对吗?
The problem is that the projects table doesn't have a field called name
or title
so the select box is empty. You wouldn't have any problems if there was a name
or a title
field, right?
解决方案,在项目模型中添加:
Well, here's the solution, in the Project model add this:
var $displayField = 'projectName';
http://book.cakephp.org/view/71/Model-Attributes
所以你是在正确的方向,只是搞砸了模型有点。我希望你现在明白了吧;]
So you were going in the right direction, just messed up the models a bit. I hope you understand it now ;]
这篇关于CakePHP的displayField用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!