Codeigniter数据传递

时间:2013-12-19 17:57:24

标签: php html codeigniter

控制器名称:mother.php

控制器功能:

public function mother_dram_print() {

    $mother = array();

    $mother['label'] = $this->load->view('mother/mother_dram', '', TRUE);

    $data = array(

        'name_1' => $this->input->post('name_1'),

        'size_1' => $this->input->post('size_1'),

        'qty_1' => $this->input->post('qty_1')

    );

    $data['label_print'] = $this->load->view('print_template', $mother, TRUE);

    $this->load->view('home', $data);
}

查看文件名:mother_dram.php

查看文件:

<div class="moth-dram-label-main-container fix">

<?php

for ($p1 = 1; $p1 <= $qty_1; $p1++) {

    echo "<div class='moth-dram-label-wrapper fix'>";

    echo "<div class='moth-dram-name fix'>$name_1</div>";

    echo "<div class='moth-dram-ml'>$size_1</div>";

    echo "</div>";

}

</div>

注意:当我从html表单提交数据时,数据无法在mother_dram.php文件中查看。

1 个答案:

答案 0 :(得分:0)

在将$data传递给$this->load->view('mother/mother_dram', $data, TRUE);

之前定义$data

从代码的样式来看,只要您在某处定义{{1}},就会认为{{1}}是沿着视图传递的,但事实并非如此。