2013-05-13 221 views
0

我無法使用Codeigniter 2.1中的窗體訪問控制器。該主頁有幾個鏈接,我可以訪問。但是當我想要以某種形式提取數據時,我會顯示403禁止的錯誤:錯誤403:禁止的錯誤

禁止您無權訪問此服務器上的/Pruebas/application/controllers/valiar.php。

的觀點:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<title>Anuncios</title> 
<link rel="stylesheet" href="/Pruebas/css/estilos.css" type="text/css" 
    media="screen"/>  
<link rel="stylesheet" href="/Pruebas/css/logestilos.css" type="text/css" 
    media="screen"/> 
</head> 

<body> 

<div id="contenedor"> 
<div id="menu"> 
    <label for="home" id="inicio"><a href="http://localhost/Pruebas/index.php 
      /cindice/">Inicio</a></label> 
    <label for="acceso" id="login"><a href="http://localhost/Pruebas/index.php 
      /cindice/publicar">Publicar anuncio</a></label> 
    <label for="reg" id="registro"><a href="http://localhost/Pruebas/index.php 
      /cindice/registro">Registro</a></label> 
    <label for="empresa" id="sobrempresa"><a href="http://localhost/Pruebas 
      /index.php/cindice/sobempresa">Sobre nosotros</a></label> 
    <label for="contacto" id="contactar"><a href="http://localhost/Pruebas 
      /index.php/cindice/contacto">Cont&aacute;ctanos</a></label> 
</div> 
</div> 

<div id="acformulario"> 
    <?php echo validation_errors(); ?> 
    <form action="http://localhost/Pruebas/application/controllers 
      /validar.php" method="post"> 
    <label for="correo" id="dcorreo">Direcci&oacute;n de correo</label> 
    <input type="text" name="drcorreo" id="dcc"/><br /><br /> 
    <label for="contrasenya" id="cont">Contrase&ntilde;a</label> 
    <input type="password" name="contrasena" id="cmcont"/><br /><br /> 

    <input type="submit" name="envia" id="bentrar" value="Entrar" />  
    </form> 
</div> 

</body> 
</html> 

控制器:

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

    class Cindice extends CI_Controller { 

function __construct() { 
    parent::__construct(); 
} 

public function index() 
{ 
    $this->load->view('indice'); 
} 

    public function validar() 
{ 
    $this->input->post('drcorreo'); 
    $this->input->post('contrasena'); 

    $this->form_validation->set_rules('correo','Direcci&oacute;n de 
      correo','trim|required|valid_email|xss_clean'); 

      $this->form_validation->set_rules('contrasenya','Contrase&ntilde;a', 
      'trim|required|md5|xss_clean'); 

    if ($this->form_validation->run()) 
    { 
     echo ("validaci&oacute;n v&aacute;lida"); 
    } 
    else { 
     $this->load->view(''); 
     echo ("validaci&oacute;n incorrecta"); 
     } 
} 

我.htacess文件有句話從所有拒絕。我怎樣才能訪問控制器?

謝謝。

回答

2

你的表單動作應該是這樣的:

<?php echo form_open('validar'); // needs the form helper to be loaded ?> 

...而不是:

<form action="http://localhost/Pruebas/application/controllers/validar.php" method="post"> 

你不能給控制器的文件路徑作爲表單操作的位置。

+2

<?php echo form_open('cindice/validar') - 爲了安全起見。 – 2013-05-13 09:51:36

+0

他的代碼有點不清楚。他似乎有一個'validar.php'控制器,但是他也有一個控制器'cindice.php'和'validar'方法。這取決於他的設置 - 但是,好,趕上:) – Mudshark 2013-05-13 09:56:49

+0

正確...但根據上面提供的代碼摘錄,表單應該提交給cindice/validar。我認爲他對CI很陌生,並濫用MVC模式。 – 2013-05-13 10:31:02