cakephp复选框命名模式

cakephp复选框命名模式,cakephp,checkbox,setting,Cakephp,Checkbox,Setting,(编辑以提供更清晰的示例) 我有cakephp模型结构的文档->节->变量 在表单中,我希望能够列出所有变量,但嵌套在文档中,然后是节级别。那一点很好 我希望在变量级别的每个项目旁边都有复选框,以允许选择变量 我希望在sectionlevel上有一个复选框,选中该复选框后,将选中该部分中变量的所有复选框 我希望在文档级别有一个复选框,这样当选中该复选框时,它将选中该文档变量的所有复选框(即在所有部分中) 为了便于实现这一点,我将复选框命名为(我设置了ID)(伪代码): 我希望,如果我选中“节级别

(编辑以提供更清晰的示例) 我有cakephp模型结构的文档->节->变量

在表单中,我希望能够列出所有变量,但嵌套在文档中,然后是节级别。那一点很好

我希望在变量级别的每个项目旁边都有复选框,以允许选择变量

我希望在sectionlevel上有一个复选框,选中该复选框后,将选中该部分中变量的所有复选框

我希望在文档级别有一个复选框,这样当选中该复选框时,它将选中该文档变量的所有复选框(即在所有部分中)

为了便于实现这一点,我将复选框命名为(我设置了ID)(伪代码):

我希望,如果我选中“节级别”复选框,我可以通过在变量级别复选框的所有id的开头使用文档id_section_id存根来设置该节的所有变量级别复选框。。。但也许我在抓救命稻草

下面是级别中的复选框示例:(为布局道歉)


当渲染时,这可能看起来像这样

<td>Select (toggle) all variables
<input type="checkbox" name="data[Project][11]"  onclick="SelectSection(this,this.name,this.checked);" value="1" id="Project11"/>
// note that checkbox id and name include ref to document id (11)
</td></tr>

<h4>Details of Health Workers at Facility</h4>

<table>
 <tr><td>Collection Method</td><td>FW completed evaluation on paper</td></tr>
<tr><td>Collection objective</td><td>blah blah blah blah</td>
<td>Select (toggle) all section variables
<input type="checkbox" name="data[Project][11_24]"  value="1" id="Project1124"/></td></tr>
// note that checkbox id and name include ref to document id (11) and section id (24)
</table>
<table>
<tr><th>Full text</th><th>Type</th><th>Format</th><th>Codeset</th></tr>
<tr><td>Site</td><td>Categorical</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_402]"  value="1" id="Project1124402"/></td></tr>
// note that checkbox id and name include ref to document id (11), section id (24) and variable id (402)
<tr><td>Facility</td><td>Categorical</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_403]"  value="1" id="Project1124403"/></td></tr>
<tr><td>Name</td><td>Text</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_404]"  value="1" id="Project1124404"/></td></tr>
<tr><td>Position of Health Worker</td><td>Text</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_405]"  value="1" id="Project1124405"/></td></tr>
<tr><td>Description</td><td>Text</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_406]"  value="1" id="Project1124406"/></td></tr>
<tr><td>Interviewer Code</td><td>Categorical</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_407]"  value="1" id="Project1124407"/></td></tr>
<tr><td>Date of Facility Visit </td><td>Date</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_408]"  value="1" id="Project1124408"/></td></tr>
</table>
选择(切换)所有变量
//注意,复选框id和名称包括对文档id(11)的引用
设施内卫生工作者的详细信息
收集方法完成纸上评估
收集对象诸如此类诸如此类
选择(切换)所有截面变量
//注意,复选框id和名称包括参考文件id(11)和章节id(24)
完整文本类型格式代码集
站点分类定量
//注意,复选框id和名称包括对文档id(11)、节id(24)和变量id(402)的引用
设施分类定量
NameTextQuantitative
卫生工作人员的职位
描述文本定量
采访者编码分类定量
设施访问日期日期定量
有人对如何处理这个问题有什么建议吗?我相信杀死这只鸟的方法不止一种

谢谢


Paul

如果我理解您的问题,只需使用
FormHelper
创建您的复选框-他们将在其
id
中包含模型,然后您可以单击使用Javascript(jQuery使其易于)修改包含“_变量”或“_部分”…等的复选框

这是我不确定Dave的最后一点。如何按部分名称“筛选”复选框(例如,使用LIKE运算符的SQL等价项)。我找不到任何关于如何按部分名称(或ID)选择复选框的信息…请作为一个与javascript相关的新问题来提问。谢谢Dave,我已经被引导到正确的解决方案中,现在可以从不同级别选择变量了。
    <?php
//Document level
//all of this within a ForEach loop for documents
echo "<table>";
echo "<tr><td>Collection dates</td><td>".$project_document['data_collection_dates']."</td>";
echo "<td>Select (toggle) all variables"
        .$this->Form->checkbox($project_document['id'], // note that this sets the chkbox id to the value of the current document id
                            array('hiddenField' => false,'onclick'=> 'SelectSection(this,this.name,this.checked);'))
                            ."</td></tr>";
echo "</table>";

foreach ($project_document['ProjectDocumentSection'] as $project_document_section): 
    echo "<h4>" .  $project_document_section['title']. "</h4>";
    echo "<table>";
    echo "<tr><td>Collection Method</td><td>" . $project_document_section['method']. "</td></tr>";
    echo "<tr><td>Collection objective</td><td>" . $project_document_section['objective']. "</td>";
    echo "<td>Select (toggle) all section variables"
            .$this->Form->checkbox($project_document['id']
                ."_".$project_document_section['id'] // and here the chkbox id is set to combination of document id and section is (using _ as separator)
                , array('hiddenField' => false))."</td></tr>";
    echo "</table>";
        echo "<table><tr><th>Full text</th><th>Type</th><th>Format</th><th>Codeset</th></tr>" ; // header for variable table
        foreach ($project_document_section['ProjectDocumentSectionVariable'] as $project_document_section_var):
            echo"<tr><td>".$project_document_section_var['variable_type'] 
                            ."</td><td>".$project_document_section_var['variable_format'] 
                            ."</td><td>";
            echo "<td>".$this->Form->checkbox($project_document['id']
                    ."_".$project_document_section['id']
                        ."_".$project_document_section_var['id'], array('hiddenField' => false))."</td></tr>";
        endforeach;
        echo "</table>";

endforeach;
// and later endforeach for the document itself

?>
<td>Select (toggle) all variables
<input type="checkbox" name="data[Project][11]"  onclick="SelectSection(this,this.name,this.checked);" value="1" id="Project11"/>
// note that checkbox id and name include ref to document id (11)
</td></tr>

<h4>Details of Health Workers at Facility</h4>

<table>
 <tr><td>Collection Method</td><td>FW completed evaluation on paper</td></tr>
<tr><td>Collection objective</td><td>blah blah blah blah</td>
<td>Select (toggle) all section variables
<input type="checkbox" name="data[Project][11_24]"  value="1" id="Project1124"/></td></tr>
// note that checkbox id and name include ref to document id (11) and section id (24)
</table>
<table>
<tr><th>Full text</th><th>Type</th><th>Format</th><th>Codeset</th></tr>
<tr><td>Site</td><td>Categorical</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_402]"  value="1" id="Project1124402"/></td></tr>
// note that checkbox id and name include ref to document id (11), section id (24) and variable id (402)
<tr><td>Facility</td><td>Categorical</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_403]"  value="1" id="Project1124403"/></td></tr>
<tr><td>Name</td><td>Text</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_404]"  value="1" id="Project1124404"/></td></tr>
<tr><td>Position of Health Worker</td><td>Text</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_405]"  value="1" id="Project1124405"/></td></tr>
<tr><td>Description</td><td>Text</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_406]"  value="1" id="Project1124406"/></td></tr>
<tr><td>Interviewer Code</td><td>Categorical</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_407]"  value="1" id="Project1124407"/></td></tr>
<tr><td>Date of Facility Visit </td><td>Date</td><td>Quantative</td>
<td><input type="checkbox" name="data[Project][11_24_408]"  value="1" id="Project1124408"/></td></tr>
</table>