Passing an object to the view in CodeIgniter I'm trying to use an object and persist it into the data base.

I created a class in the library's folder.

&lt;?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-&gt;categoria = 1;
        $this-&gt;consecutivo = 1;
        $this-&gt;mensaje = "Mensaje por defecto";
    }

    public function escalarSolicitud( User $actual, User $nuevo){
        $this-&gt;setSolicitante($nuevo);
    }

    # Getters and Setters

    public function setCategoria( $categoria ){
        $this-&gt;categoria = $categoria; 
    }

    public function getCategoria(){
        return $this-&gt;categoria;
    }    


Here is the Controller:

&lt;?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-&gt;session-&gt;userdata('session_user');   
        $usuario      = $session_data['usuario']; 
        $categoria    = $this-&gt;input-&gt;post('category');
        $mensaje      = $this-&gt;input-&gt;post('description');

        $solicitud = new solicitud;

        $solicitud-&gt;setSolicitante($user);
        $solicitud-&gt;setCategoria($categoria);
        $solicitud-&gt;setMensaje($mensaje);

        $this-&gt;helpdesk_model-&gt;createSupport( $solicitud );
    }


And in the Model how can I use the object properties:

public function createSupport( $soporte ){

    $this-&gt;db-&gt;trans_start();

        $data = array(
            'id' =&gt; null,  
            'id_user' =&gt; $soporte[usuario], ???
            'id_category' =&gt; $soporte[categoria], ???
            'message' =&gt; $soporte[mensaje] ???
        ); 

        $this-&gt;db-&gt;insert('supports', $data); 

    $this-&gt;db-&gt;trans_complete();

    return $this-&gt;db-&gt;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?
I would like to add something to @Dukeatcoding comment in the question.  What is the point of passing the whole object? Thinking on it as a part of the main controller, you should only pass the data as an array to the model:

$data = array(
    'id_user'     =&gt; $usuario,
    'id_category' =&gt; $soporte-&gt;getCategoria
    'message'     =&gt; $soporte-&gt;getMensaje
)
$this-&gt;helpdesk_model-&gt;createSupport( $solicitud );


Although, as you are getting all these properties so often, what about a general getter in your soporte class?

public function getValue( $var ){
    return $this-&gt;{$var};
}   


And you'd have something like:

$data = array(
    'id_user'     =&gt; $soporte-&gt;getVar( 'usuario'),
    'id_category' =&gt; $soporte-&gt;getVar( 'categoria'),
    'message'     =&gt; $soporte-&gt;getVar( 'mensaje' )
)


From your code, I would take care of the validation of your values, as it looks like you don't validate if they're numeric, if they exists on your DDBB, etc. Maybe you're doing it, because I suppose the code you posted is just a excerpt (due to some method are missed in Solicitud, as setSolicitante($nuevo) ), but I prefer to write it, just in case.

Also, I won't assign to a var the values you take directly, just call them an take the value:

//Instead of:
$session_data = $this-&gt;session-&gt;userdata('session_user');   
$usuario      = $session_data['usuario']; 
// Better 
$usuario      = $this-&gt;session-&gt;userdata('session_user');  


Off topic, you could check Doctrine, http://www.doctrine-project.org/projects/orm.html, is an ORM that maybe could help you, and it has its own CI recipe:
http://docs.doctrine-project.org/en/2.0.x/cookbook/integrating-with-codeigniter.html

Have fun!