Welcome Guest, Not a member yet? Register   Sign In
How can I know if a model exist
#1

Hi, I need 2 things, 

1 - Know if a file exist in models folder.

2 - Call or load a model with a very specific constructor.

I've tried absolute and relative routes with is_file and file_exist but it doesn't work.

And tried to call the other model, this way:

$modelo = new Nomenclators_M('carreras');

But I get this error:

Class Nomenclators_M not found.

Here is some code so you get an idea:

$archivo = '../models/' . ucfirst(static::$prefix) . 'M.php';

if(file_exist($archivo)){

$modelo = static::$prefix . 'm';

}else{

$modelo = new Nomenclators_M('carreras');

}

$data['things'] = $this->$modelo->all_data();
Reply
#2

I answer myself just in case anyone have the same problem

Just add a modification in MY_Model constructor

if(!empty($tatic::$table_name)
static::$fields = get_fields();

After that, add a set_data($table) function

And there we go:

if(!class_exist(ucfirst(static::$prefix) . 'M'){

$this->load->model('nomenclators_m');
$this->nomenclators_m->set_data(trim(static::$prefix, '_'));
Reply




Theme © iAndrew 2016 - Forum software by © MyBB