Estoy haciendo un script en MVC PHP , estos son mis datos
datosController.php
<?php
class datosController extends Controller{
public function __construct()
{
parent::__construct();
}
public function index(){
$objDatos=$this->loadModel('datos');
$this->_view->lista=$objDatos->getDatos();
$this->_view->renderizar('index');
}
public function registrar()
{
$userName = trim($_POST['userName']);
$firstName = trim($_POST['firstName']);
$lastName = trim($_POST['lastName']);
$email = trim($_POST['email']);
$pass = trim($_POST['pass']);
$objDatos = $this->loadModel('datos');
$objDatos->ingresar($userName, $firstName,$lastName,$email,$pass);
//$this->redireccionar('datos/index');
$this->_view->renderizar('registrar');
}
}
?>
# datosModel.php
<?php
class datosModel extends Model
{
public function __construct()
{
parent::__construct();
}
public function getDatos(){
$sql="SELECT * FROM Users;";
$result=$this->_db->query($sql) or die("Error en el query : $sql");
return $result;
}
public function ingresar($userName, $firstName,$lastName,$email,$pass)
{
$sql = "INSERT INTO Users (userName,firstName,lastName,email,pass) VALUES($userName, $firstName,$lastName,$email,$pass));";
//echo $sql;
$result = $this->_db->query($sql) or die("Error en el query : $sql");
return;
}
}
?>
# index.phtml
<!--PAGE CONTENT -->
<div id="content">
<div class="inner">
<div class="row">
<div class="col-lg-12">
<h2> Data Tables </h2>
</div>
</div>
<hr />
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
DataTables Advanced Tables
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th><?php echo _('Usuario')?></th>
<th><?php echo _('Apellidos')?></th>
<th><?php echo _('Nombres')?></th>
<th><?php echo _('Correo')?></th>
<th><?php echo _('ClaveUsuario')?></th>
<th><?php echo _('Opciones')?></th>
</tr>
</thead>
<tbody>
<?php
while ($reg = $this->lista->fetch_object())>
<tr class="odd gradeX">
<td><?php echo $reg->userName?></td>
<td><?php echo $reg->lastName?></td>
<td><?php echo $reg->firstName?></td>
<td><?php echo $reg->email?></td>
<td><?php echo $reg->pass?></td>
</tr>
<?php endwhile;?>
</tbody>
</table>
<td><a href="<?php echo BASE_URL?>datos/registrar/<?php echo $reg->userName?>" class="btn btn-primary active" id="signup" role="button"><?php echo _('Encuesta')?></a>
</div>
</div>
</div>
</div>
</div>
</div>
<!--END PAGE CONTENT -->
NOTA: EN ESTA FORMULARIO CUANDO LE DOY CLIC EN ENCUESTA Y DEBE PASAR AL FORMULARIO INGRESAR PARA RELLENAR LOS NUEVO DATOS ME SALE UN ERROR:
Notice: Undefined index: userName in /var/www/html/Sesion04/controllers/datosController.php on line 20 Notice: Undefined index: firstName in /var/www/html/Sesion04/controllers/datosController.php on line 21 Notice: Undefined index: lastName in /var/www/html/Sesion04/controllers/datosController.php on line 22 Notice: Undefined index: email in /var/www/html/Sesion04/controllers/datosController.php on line 23 Notice: Undefined index: pass in /var/www/html/Sesion04/controllers/datosController.php on line 24 Error en el query : INSERT INTO Users (userName,firstName,lastName,email,pass) VALUES(, ,,,));
FORMULARIO INGRESAR
# registrar.phtml
<!--PAGE CONTENT -->
<div id="content">
<div class="inner">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header"><?php echo _('Edicion')?></h1>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<?php echo _('Datos ')?>
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<form role="form" action="<?php echo BASE_URL?>datos/registrar" id="form_editar" method="post">
<div class="form-group">
<label><?php echo _('Codigo')?></label>
<input class="form-control" type ="text" name="userName" id="userName" value="<?php echo $this->ingresar->userName?>" >
</div>
<div class="form-group">
<label><?php echo _('Nombre')?></label>
<input class="form-control" type ="text" name="lastName" id="lastName" value="<?php echo $this->ingresar->lastName?>">
</div>
<div class="form-group">
<label><?php echo _('apellido')?></label>
<input class="form-control" type ="text" name="firstName" id="firstName" value="<?php echo $this->ingresar->firstName?>">
</div>
<div class="form-group">
<label><?php echo _('Correo')?></label>
<textarea class="form-control" rows="5" name="email" id="email"><?php echo $this->ingresar->email?></textarea>
</div>
<div class="form-group">
<label><?php echo _('Password')?></label>
<input class="form-control" type ="text" name="pass" id="pass" value="<?php echo $this->ingresar->pass?>">
</div>
<div id="zona_mensajes">
</div>
<button type="button" id="btn_enviar" class="btn btn-default"><?php echo _("Registrar")?></button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--END PAGE CONTENT -->
ESPERO QUE ME PUEDAN APOYAR , GRACIAS.