我有一个表单,在submited之后加载另一个表单(来自其他控制器的另一个视图)。然而,在这第二种形式中,我不知道为什么表单验证规则(以前面的形式实现)不起作用,为什么在提交时我总是找不到页面。 对此,我试图加载两个不同模型的页面通常在URL中。什么情况是,如果在第一视图模型,如果我在URL中写:codeigniter从不同文件夹加载视图
http://localhost/code/index.php/fichas/index
他加载此或其他页面fichas文件夹没有问题,如果我尝试第二个模型(Produtos)像这只是测试:
http://localhost/code/index.php/produtos/index
在这个页面或其他produtos文件夹我总是得到页面未找到。我错过重要的事情吗?为什么他应该能够加载一些视图,我已经在“视图”中的某些文件夹中而不是其他视图中?
谢谢!
的index.php我这种形式的开始(create.php)后::fichas.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>
函数创建(控制器):
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);
}
}
一些代码EDIT
从以前的功能我重定向到产品/ 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():表单验证从不起作用,并且提交后的加载视图始终无法找到页面。这就是为什么我试图单独加载产品模型的观点。
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我复制的基础从类Fichas,所以我不得不在类Produto如下:
class Fichas extends CI_Controller { ...
非常感谢您的帮助无论如何,这让我失去了很多时间,但至少现在它已经解决了。
为你所做的事发布一些代码。 – Rooneyl
完成Rooneyl,请看看! – user1511579
而不是在第一种形式的成功加载视图,做一个重定向('produtos/ponto');您可以通过将数据放入flashdata来传递数据。让我知道这是否有效。 – Rooneyl