y quiero simplemente ver como insertar datos en la BD. Sin framework para mi es una tarea facil, pero tengo que aprender de este framework.
Tengo
mi controlador
bienvenido:
Código PHP:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Bienvenido extends CI_Controller {
public function index()
{
$this->load->helper(array('form', 'url', 'date'));
$this->load->model('modelo');
$this->load->view('formulario');
}
function profile()
{
$data['regiones_select'] = $this->modelo->fill_dropdown('regiones', 'codigo,nombre');
}
}
mi vista
formulario
Código PHP:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bienvenido</title>
</head>
<body>
<div>
<h1>Bienvenidos</h1>
<?php echo form_open(' ');?>
<?php
$names = array(
'name' => 'username',
'id' => 'username',
'maxlength' => '30',
'size' => '30',
);
@$region = $regiones_select;
$id = 'id="region" '; //agregamos id a select region
$uregion_code='1';
?>
<table>
<tr>
<td><?php echo form_label('Nombre:', 'username'); ?></td>
<td><?php echo form_input($names); ?><td>
</tr>
<tr>
<td><?php echo form_label('Region:','region');?></td>
<td><?php echo form_dropdown('region', $region, $uregion_code,$id); ?></td>
</tr>
</table>
</div>
</body>
</html>
modelo
Código PHP:
<?php
class Modelo extends CI_Model{
var $title = '';
var $content = '';
var $date = '';
function __construct() {
parent::__construct();
}
function get_data($table, $what = NULL, $where = NULL, $identifier = NULL, $orderby = NULL, $ordertype = NULL, $limit = NULL){
$data='';
if($what && $what != '*'){
$this->db->select($what);
if($where)
$this->db->where($where, $identifier);
if($orderby)
$this->db->order_by($orderby, $ordertype);
if($limit)
$this->db->limit($limit);
$query = $this->db->get($table);
foreach ($query->result_array() as $tablerow) {
$data[] = $tablerow[$what];$this->db->where($where, $identifier);
}
}else{
if($where)
$this->db->where($where, $identifier);
if($orderby)
$this->db->order_by($orderby, $ordertype);
$query = $this->db->get($table);
$data = $query->result_array();
}
return $data;
}
function get_userdata($what, $user_id){
$this->db->select($what);
$this->db->where('id', $user_id);
$query = $this->db->get('users');
$user = '';
foreach ($query->result_array() as $tablerow) {
$user = $tablerow[$what];
}
return $user;
}
function fill_dropdown($table, $data){
$this->db->select($data);
$query = $this->db->get($table);
$ddmenu = array();
$ddmenu[''] = 'Seleccione';
$fields = explode(',', $data);
foreach ($query->result_array() as $tablerow) {
$index = $tablerow[$fields[0]];
$source = $tablerow[$fields[1]];
$ddmenu[$index] = $source;
}
return $ddmenu;
}
function insert_entry($table, $data)
{
$this->db->insert($table, $data);
}
function update_entry($table, $data, $key, $key_value)
{
$this->db->update($table, $data, array($key => $key_value));
}
}
la idea es que quiero mostrar en el combobox registros de la base de datos.
-....pero esto no me funciona...que estare haciendo mal???