I'm trying to use an object and persist it into the data base.
I created a class in the library's folder.
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Solicitud {
private $categoria;
private $consecutivo;
private $id;
private $mensaje;
private $solicitante;
function __construct(){
$this->categoria = 1;
$this->consecutivo = 1;
$this->mensaje = "Mensaje por defecto";
}
public function escalarSolicitud( User $actual, User $nuevo){
$this->setSolicitante($nuevo);
}
# Getters and Setters
public function setCategoria( $categoria ){
$this->categoria = $categoria;
}
public function getCategoria(){
return $this->categoria;
}
Here is the Controller
:
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Administrador extends Ci_Controller {
function __construct(){
parent::__construct();
}
public function crearSolicitud(){
$session_data = $this->session->userdata('session_user');
$usuario = $session_data['usuario'];
$categoria = $this->input->post('category');
$mensaje = $this->input->post('description');
$solicitud = new solicitud;
$solicitud->setSolicitante($user);
$solicitud->setCategoria($categoria);
$solicitud->setMensaje($mensaje);
$this->helpdesk_model->createSupport( $solicitud );
}
And in the Model
how can I use the object properties:
public function createSupport( $soporte ){
$this->db->trans_start();
$data = array(
'id' => null,
'id_user' => $soporte[usuario], ???
'id_category' => $soporte[categoria], ???
'message' => $soporte[mensaje] ???
);
$this->db->insert('supports', $data);
$this->db->trans_complete();
return $this->db->trans_status();
}
I need to know if I'm in the right direction or if the use of the 'Solicitud' class is not necessary. If I'm right, how should I call in the model the object attributes?
'id_category' => $soporte->getCategoria();
– AndreFontaine Feb 5 '14 at 14:51