0

我有一个表单,提交后会加载另一个表单(来自其他控制器的另一个视图)。但是,在第二个表单中,我不知道为什么表单验证规则(如在前一个表单中实现)不起作用以及为什么在提交中我总是找不到页面。关于这一点,我尝试在 url 中正常加载两个不同模型的页面。发生的情况是,如果在第一个视图的模型中,如果我在 url 中写入:

http://localhost/code/index.php/fichas/index

如果我尝试像这样的第二个模型(产品)只是为了测试,他会毫无问题地在 fichas 文件夹中加载此页面或其他页面:

http://localhost/code/index.php/produtos/index

在此页面或其他产品文件夹中,我总是找不到页面。我错过了什么重要的东西吗?为什么他应该能够加载我在“视图”内的某些文件夹中拥有的一些视图而不是其他视图?

谢谢!

用一些代码编辑:

在 index.php 之后,我从这个表单(create.php)开始:

    <h2>Nova Ficha de Segurança</h2>

<?php echo validation_errors(); ?>

<?php echo form_open('fichas/create') ?>

<label for="cod_produto">Código do Produto:</label>
    <input type="input" name="cod_produto" /><br />

    <label for="nome_produto">Nome do Produto:</label> 
    <input type="input" name="nome_produto" /><br />

    <label for="versao">Versão:</label>
    <input type="input" name="versao" /><br />

    <label for="data_ficha">Data da Ficha:</label>
    <input type="input" name="data_ficha" /><br />

    <input type="submit" name="submit" value="Criar Ficha" /> 

</form>

fichas.php(控制器)的函数创建:

public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');

$this->form_validation->set_rules('versao', 'versao', 'required');

if ($this->form_validation->run() === FALSE)
{
    //$this->load->view('templates/header', $data); 
    //$this->load->view('templates/header');    
    $this->load->view('fichas/create');
    //$this->load->view('templates/footer');

}
else
{
    $data['teste1']=$this->fichas_model->set_fichas();
    $data['teste'] = $this->fichas_model->get_distribuidor();
    $this->load->view('produtos/ponto',$data);
}
}

从上一个函数我被重定向到 produtos/ponto 文件:

<h2>Identificação do Produto/Identificação da Empresa</h2>

<?php echo validation_errors(); ?>

<?php echo form_open('produtos/ponto') ?>

    <label for="nome_produto">Nome do Produto:</label> 
    <input type="input" name="nome_produto" /><br />

    <label for="descricao_produto">Descrição do Produto:</label>
    <input type="input" name="descricao_produto" /><br />

    <label for="id_ficha">Cod do Produto:</label>
    <input type="input" name="id_ficha" value="<?php echo $teste1['id_ficha'];?>" /><br />

    <h4>Distribuidor</h4>

    <label for="nome_empresa">Nome da Empresa:</label>
    <input type="input" name="nome_empresa" value="<?php echo $teste['nome_empresa'];?>" /><br />

    <label for="morada">Morada:</label>
    <input type="input" name="morada" value="<?php echo $teste['morada'];?>" /><br />

    <label for="cod_postal">Código Postal:</label>
    <input type="input" name="cod_postal" value="<?php echo $teste['cod_postal'];?>" /><br />

    <label for="localidade">Localidade:</label>
    <input type="input" name="localidade" value="<?php echo $teste['localidade'];?>" /><br />

    <label for="telefone">Telefone:</label>
    <input type="input" name="telefone" value="<?php echo $teste['telefone'];?>" /><br />

    <label for="fax">Fax:</label>
    <input type="input" name="fax" value="<?php echo $teste['fax'];?>" /><br />

    <label for="email">E-mail:</label>
    <input type="input" name="email" value="<?php echo $teste['email'];?>" /><br />

    <input type="submit" name="submit" value="Seguinte" /> 

</form>

最后,produtos 控制器中的函数 ponto():表单验证从不工作,提交后的加载视图总是找不到页面。这就是为什么我试图单独加载 produtos 模型的视图。

    public function ponto()
{


$this->load->helper('form');
$this->load->library('form_validation');

//$data['title'] = 'Create a news item';

$this->form_validation->set_rules('nome_produto', 'Nome do Produto', 'required');
$this->form_validation->set_rules('morada', 'Morada', 'required');



if ($this->form_validation->run() === FALSE)
{
    //$this->load->view('templates/header', $data); 
    //$this->load->view('templates/header');    
    $this->load->view('produtos/ponto');
    //$this->load->view('templates/footer');

}
else
{
    $this->produtos_model->set_produtos();
    $this->load->view('produtos/success');
}
}

解决了:

当我创建类 Produtos 时,我从 Class Fichas 中复制了基础知识,因此我在 Class Produto 中有以下内容:

class Fichas extends CI_Controller { ...

无论如何,非常感谢您的帮助,这让我失去了很多时间,但至少现在它已经解决了。

4

1 回答 1

0

您的第二个模板似乎根本没有像第一个模板那样的表单开始/结束标记。

于 2013-01-03T11:25:53.403 回答