我试图创建一个用户选择了他们创建的模板编号的视图,然后将其带到下一页,在该页面中显示他们为该模板创建的字段。我有我的sql语句执行我希望他们做的事情,但我不确定如何将表单打印出这些custom
字段default_values
到输入框
发票表包含id sender_id receiver_id template_id
字段表包含id name default_value active template_id
invoices hambt fields
fields hambt invoices
联接表是fields_invoices,它包含id invoice_id field_id entered value
我不确定如何从发票表和字段表中获取id以保存到连接表
public function create($id)
{
$this->set('title_for_layout', 'Create Invoice');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.png');
$this->layout='home_layout';
if (!is_numeric($id)) throw new BadMethodCallException('I need an ID');
$this->Invoice->id = $id;
if (!$this->Invoice->exists()) throw new NotFoundException('Invalid ID');
$this->set('invoice_id',$id);
$names = $this->Invoice->find('list',array(
'fields'=>array('template_id'),
'conditions'=>array('id'=>$id)));
$fields = $this->Field->find('list', array(
'conditions'=>array(
'template_id'=>$names)));
$this->set('field',$fields);
$this->set('name',$names);
if(empty($this->data)){
$this->data= $this->Field->read($fields);
}
else{
if(($this->Field->save($this->data)))
{
$this->Session->setFlash('The field has been updated');
$this->redirect(array('controller'=>'invoices', 'action'=>'index'));
}
}
}
这是视图
<?php echo $this->Form->create('fields_invoices'); ?>
<?php foreach ($field as $fields): ?>
<?php echo $this->Form->Input($fields); ?>
<?php endforeach ;?>
<?php echo $this->Form->End('Submit');?>
现在我不确定如何正确编码视图并获取它以便将default_variables
表格中的fields
打印到input boxes
。任何帮助将不胜感激
答案 0 :(得分:0)
你能为我们调试$ fields数组吗?
您可以在自动生成的输入字段中指定所需内容...
ie:$ this-&gt; Form-&gt; input(&#39; field_name&#39;,array(&#39; label&#39; =&gt;&#39;无论你想叫什么&#39; ;,&#39;值&#39; = GT;&#39;值&#39;));