Buenas. Tengo el problema de que quiero listar determinados datos de una BD MySQL en Codeigniter y no me devuelve absolutamente nada.
Les dejo el código que estoy usando:
loginController.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class loginController extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('categoriasModel');
}
public function index()
{
$datos['arrCategorias'] = $this->categoriasModel->get_categorias();
$this->load->view('login_index', $datos);
}
}
categoriasModel.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class categoriasModel extends CI_Model {
public $variable;
public function __construct()
{
parent::__construct();
}
function get_categorias(){
$query = $this->db-> query('SELECT id_categoria,nombre_categoria FROM categorias');
if ($query->num_rows() > 0) {
foreach($query->result() as $row){
$arrDatos[htmlspecialchars($row->id_categoria, ENT_QUOTES)] = htmlspecialchars($row->nombre_categoria, ENT_QUOTES);
}
$query->free_result();
return $arrDatos;
}
}
login_index.php
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Disquerias La Roberta</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<style>
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #eee;
}
.form-signin {
max-width: 330px;
padding: 15px;
margin: 0 auto;
}
.form-signin .form-signin-heading,
.form-signin .login {
margin-bottom: 10px;
}
.form-signin .login {
font-weight: normal;
}
.form-signin .form-control {
position: relative;
height: auto;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 10px;
font-size: 16px;
}
.form-signin .form-control:focus {
z-index: 2;
}
.form-signin input[type="text"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.form-signin input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
</style>
</head>
<body>
<div class="container">
<form class="form-signin">
<h2 class="form-signin-heading">Iniciar sesion</h2>
<label for="inputLogin" class="sr-only">Login</label>
<input type="text" id="inputEmail" class="form-control" placeholder="Nombre de usuario" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<div class="login">
<select class="form-control">
<?php
foreach ($arrCategorias as $i => $categoria)
echo '<option values="'.$i.'">'.$categoria.'</option>';
?>
</select>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Entrar</button>
</form>
</div>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body>
</html>
Espero una respuesta ya que desde hace varios dias ando con este problema. Saludos!