切换控制器和发送数据编码


Switching controllers and sending data in codeigniter

我必须开发一个内部基于web的应用程序与编码器,我需要链不同的形式(生成与以前的形式选择的数据)。现在,我试图在控制器的相同方法中使用表单验证,但链接只验证第一个表单,我也尝试了$_SESSION变量,但我必须在每个表单之间发送大量数据。我尝试了类变量(在控制器和模型),但每次表单发送变量初始化…所以我想知道是否有一种方法从一个方法切换到另一个在我的控制器给数据的新控制器。

my first form:

<p>Filtres: </p>
        <br/><br/>
        <form action="" method="post" id="form_ajout_manip" >
        <label for="thematique[]">Thématique</label><br/>
        <select name="thematique[]" size="20" multiple>
        <?php
            foreach($list_thema->result() as $thema)
            {
                echo "<option value='".$thema->THEMATIQUE_ID."'>".$thema->PARENT_THEMATIQUE_ID." - ".
                $thema->NOM."</option>";
            }
        ?>
        </select>
        <input type="hidden" value="true"/>
        <br/>
        <br/>
        <br/>
            <input type="submit" value="Rechercher" />
        </form>

我的第二个形式:

<form action="" method="post" id="form_ajout_manip_cdt">
<label for="nom_manip" >Nom manipulation: </label>
<br/>
<input type="text" name="nom_manip"/>
<TABLE border="1">
  <CAPTION><?php echo $data->num_rows.'  '; ?>resuuultat</CAPTION>
  <TR>
    <?php
    foreach($data->list_fields() as $titre)
    {
        echo '<TH>'.$titre.'</TH>';
    }
    ?>
  </TR>
<?php
    foreach($data->result() as $ligne)
    {
        echo '<TR>';
        foreach($ligne as $case)
        {
            echo '<TD>'.$case.'</TD>';
        }
        echo '<TD><input type="checkbox" name="cdt[]"  value="'.$ligne->ID_CANDIDAT.'"
                checked="true"</TD>';
        echo '</TR>';
    }
?>
</TABLE>
<br/><br/>
<input type="submit" value="créer"/>
</form>

这是我的控制器

的两个方法
public function choix()
{
    //controller for the second form
    $this->info_page['title']='Ajout manipulation';
    $this->load->view('ui_items/header',$this->info_page);
    $this->load->view('ui_items/top_menu'); 
    $this->load->view("manipulation/choix",$data);
}
public function filtre()
{
    //controller for the first form
    $this->form_validation->set_rules('thematique[]','Thematique','');
    if($this->form_validation->run())
    {
            $data['data']=$this->manipulation_mod->select_par_filtre($this->input->post('thematique'));
            //need to send $data to the second method "choix()"
    }
    else
    {
        $this->info_page['title']='Filtre ajout manipulation';
        $this->load->view('ui_items/header',$this->info_page);
        $this->load->view('ui_items/top_menu');
        $data= array();
        $data['list_op']= $this->candidat_mod->list_operateur();
        $data['list_thema']= $this->thematique_mod->list_all_thematique();
        $data['list_gene']= $this->candidat_mod->list_gene();
        $this->load->view('manipulation/filtre', $data);
    }
}

你知道吗?

根据你的说明,让我给你一个工作大纲

<<h2>视图/h2>

将两个表单放在同一页

<? if(!$filtered): ?>
<input type="hidden" name="filtered" value="true"/>
/*  Form 1 content here  */
<? else: ?>
<input type="hidden" name="filtered" value="true"/>
/*  Form 2 content here */
<? endif; ?>
h2控制器

你只需要使用一个控制器

public function filter() {
    $filtered = $this->input->post('filtered');
    $data['filtered'] = $filtered;
    if(empty($filtered)) {
        /*  Form validation rules for Form 1    */
        /*  Run form validation etc. */
        /*  Set title etc. for Form 1   */
    } else {
        /*  Form validation rules for Form 2    */            
        /*  Run form validation etc. */
        /*  Set title etc. for Form 2   */        
    }
    /*  Load view  */
}

可能有更好的方法来做到这一点,但我相信这将工作。好运!