Codeigniter: Simple echo of data from DB

What is the best way to create my model so I can call it from my controller like this?

$this->model_model->function->dbname

I have the following model but its rubbish:

Model:

function systemName()
{

    $query = $this->db->query("SELECT cms_name FROM options");

    return $query->result();
}

Update:

function systemOptions($options)
{   
    $this->db->select($options);

    $query = $this->db->get('options');

    return $query->num_rows();
}

Answers


Why would you want to? Why not call it like this?:

 $this->model_model->functionname('dbname');

A complete skeleton of a model is like this:

<?php
class Mymodel extends Model
{
    function get_some_entries($number_rows)
    {
            return $result = $this -> db -> query("SELECT id, name
                                            FROM tablename
                                            LIMIT $number_rows");
    }
}
?>

Best way? You can probably read on CodeIgniter general guide and alter to your situation. But the basic idea is that, you create the model class then load from your controller. Then just call the model function accordingly. For example,

class Custom_model extends CI_Model {


function __construct()
{
    parent::__construct();
}

function systemName()
{

    $query = $this->db->query("SELECT cms_name FROM options");
    return $query->result();
}

...
...

function systemOptions($options)
{   
    $this->db->select($options);

    $query = $this->db->get('options');

    return $query->num_rows();
}


}

<?php
class CustomController extends CI_Controller {

public function __construct()
{
    parent::__construct();       
    $this->load->model('custom_model', 'fubar');
}

public function index()
{
    $result = $this->fubar->systemName('dbname'); 
    print_r ($result);
}

}
?>

Need Your Help

Generic interface as a method parameter and seeing fields

c#

This is probably my naivety showing through, but anyway...

Java printing directly to a Postscript network printer

java networking printing postscript

I've got Postscript code/data (?) in memory (in a Java Tomcat webapp) that I'd like to send directly to a networked PS printer. Is there an easy way (i.e. just popping open a port and sending the ...