0
我正在创建一个消息控制器,允许用户发送消息给其他用户。这里是我的数据库结构automagic下拉框不填充cakephp
用户
id
username
password
消息
id
to_id
from_id
subject
message
的to_id和from_id的用户均引用ID列。这是我的消息
消息
<?php
class Message extends AppModel {
var $name = 'Message';
var $displayField = 'subject';
var $validate = array(
'id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'to_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
'allowEmpty' => false,
'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'from_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
'allowEmpty' => false,
'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
);
var $belongsTo = array(
'Sender' => array(
'className' => 'User',
'foreignKey' => 'to_id'
),
'Recipient' => array(
'className' => 'User',
'foreignKey' => 'from_id'
)
);
}
模型当年这里是我的看法
<div class="messages form">
<?php echo $this->Form->create('Message');?>
<fieldset>
<legend><?php __('Add Message'); ?></legend>
<?php
echo $this->Form->input('to_id');
echo $this->Form->input('from_id');
echo $this->Form->input('subject');
echo $this->Form->input('message');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
</div>
<div class="actions">
<h3><?php __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('List Messages', true), array('action' => 'index'));?></li>
</ul>
</div>
它显示一个下拉框,但它没有用户。我在用户表ATLEAST 5个用户
即使我添加像这样
echo $this->Form->input('Sender.to_id');
echo $this->Form->input('Recipient.from_id');
仍然前缀不起作用
你的回答稍微不正确 - $ froms和$ tos会自动填充选择框。否则你需要一个手动'选项'=> $发件人等 – mark
我现在不能测试它,但不是,它应该像这样工作,因为关联 – kaklon
标记是正确的,单独的关联是不行的。 –