0

So I just started to use Codeigniter, and can't understand why what I'm doing isn't working.

My controller is like that:

class Tienda extends CI_Controller {

    public function index(){
        $this->load->view('inicio_view');
    }
    public function entrar(){
        $nom= $this->input->post('nom');
        $pass= $this->input->post('pass');

        if($nom && $pass){
            $data['nom']=$nom;
            $data['pass']=$pass;
            $this->load->model('Login_model');
            $user=$this->Login_model->get_usuario($nom, $pass);

            var_dump($user);

            if ($user[0]['id']=='1'){
                $this->load->view('Catalogo_view');
            }
        }
    }
}

My initial view

    <html>
    <head>
        <meta charset="utf-8">
        <title>TIENDA</title>
    </head>
    <body>
        <h1>TIENDA</h1>
        <div class="form">
            <form action="<?php echo base_url('Tienda/entrar');?>" method="post">
              Usuario: <input type="text" name="nom"/>
              <br/>
              Contraseña: <input type="text" name="pass"/>
              <br/>
             <input type="submit" value="Enviar" />
            </form>
        </div>

    </body>
    </html>

And in the login_model I'm just calling to get the user and the pass

class Login_model extends CI_Model {

        public function get_usuario($nom,$pass){
            //$query = $this->db->get_where('usuarios',array('nom'=>$nom,'pass'=>$pass));
            $query = $this->db-> query('SELECT id FROM usuarios where nom = "'.$nom.'" and pass = "'.$pass.'";');
            return $query->result_array();
        }
}

I don't know how many hours I've been searching and changing things, but it still doesn't work. Also, I checked almost every post of people who had that problem, but still can't make it work.

My catalog_view is just a h1 that says it works, because I just wanted to see if I can make it work but... I just don't know what it's happening. If there's any help here, it would be appreciated!

Alba
  • 11
  • 4

2 Answers2

0

Your code looks okay to me. I can suggest you few checklists.

  1. Make sure Controller and model file names must match with the class name. Tienda.php and Login_model.php.
  2. View file name in lower case and while loading it also follow the same case catalogo_view.php and the file must be present inside the /application/view/ directory. If you are using any sub-directory the $this->load->view('mydir/catalogo_view').
  3. While accessing URL: please make sure you have given the right URL and in lower case. http://your-url/tienda/entrar, if it doesn't work then try http://your-url/index.php/tienda/entrar.
  4. Please make sure you have configured base_url and .htaccess properly. Here I am giving you link to access few resources for more information. https://www.codeigniter.com/userguide3/general/urls.html https://gist.github.com/philipptempel/4226750
Bikram Pahi
  • 1,107
  • 1
  • 12
  • 33
  • Nothing works... Could it be a problem with my xampp? Ok, I have other projects from my class and all of them work, but mine isn't, and everything is the same. – Alba May 30 '17 at 12:57
0

Posting the answer in case anyone needs it. In config, I had to put "localhost/index.php/Tienda" so it works now.

Alba
  • 11
  • 4