[eluser]Reynolds[/eluser]
Guys,
just want to ask, what do you think of this approach?
I've made two helpers for loading models and views
-- model_helper.php
Code:
function model($model_name, $model_alias = "",$auto_connect = FALSE)
{
$ci = get_instance();
$ci->load->model( $model_name .DEFAULT_MODEL_SUFFIX, $model_alias , $auto_connect);
}
-- view_helper.php
Code:
function view($data = "", $view = "")
{
$page_view = "";
if(!empty($view))
{
$page_view = "_" . $view;
}
//$params['data'] = $data;
$ci = get_instance();
$ci->load->view( strtolower( get_class($ci) ) . DEFAULT_VIEW_SUFFIX . $page_view, $data );
}
this way I can load models and views like this
Code:
function index()
{
model('query_analyzer','qa');
$data = array(
'first' => $this->qa->show_process_list()->result(),
'second' => 2
);
view($data);
}
Generally the advantage of this is that I need no more type $this->load->*
The dis-advantage however is that it doesn't look purely OOP anymore.
I'm thinking this makes my controller methods less in size and more friendly (personally).
I'd like to do this as well with $this->load->library().
Criticism is highly appreciated, thanks