Welcome Guest, Not a member yet? Register   Sign In
Call model not work
#1

Hi,

I find myself trying codeigniter 3, but I have a very rare problem.

I have the following classes:
PHP Code:
class Recursos extends CI_Controller {
    public function 
__constructor(){
 
       parent::__construct();
 
       $this->load->model('permisos_model');
 
       $this->load->model('recursos_model');
    }
    public function 
index(){
        
$data = array('title' => 'Módulos del Sistema''contenido' => 'welcome''data1' => '');
        
// $list = $this->permisos_model->getAllRecursosParent(0); <-Here if you work
        
$list $this->recursos_model->getAllRecursosParent(0);
        
$this->load->view('admin/layout',$data);
    } 

and my model is:

PHP Code:
class Recursos_model extends CI_Model{
    public function 
__construct() {
        
$this->load->database();
    }

    public function 
getAllRecursosParent($parent){
        
$sql "select * from tab_recursos where idparent = '".$parent."'";
        return 
$this->db->query($sql);
    } 

PHP Code:
class Permisos_model extends CI_Model{
    public function 
__construct() {
        
$this->load->database();
    }
    public function 
getAllRecursosParent($parent){
        
$sql "select * from tab_recursos where idparent = '".$parent."'";
        return 
$this->db->query($sql);
    } 

With Recuros_model does not work, however, with Permisos_model if it does.

What do you think the problem is?
Reply
#2

What doesn't work? Do you get an error?
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#3

(01-03-2017, 11:17 AM)albertleao Wrote: What doesn't work? Do you get an error?

This error is:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Recursos::$recursos_model
Filename: controllers/Recursos.php
Line Number: 12
Backtrace:
File: C:\xampp\htdocs\invent\application\controllers\Recursos.php
Line: 12
Function: _error_handler
File: C:\xampp\htdocs\invent\index.php
Line: 315
Function: require_once
Reply
#4

I use acl for restriction over hook:

class ACL {
private $perms;
private $role_field;
private $CI;
public function __construct() {
$this->CI =&get_instance();
if (!isset($this->CI->session))
{ # Sessions are not loaded
$this->CI->load->library('session');
}
if (!isset($this->CI->router))
{ # Router is not loaded
$this->CI->load->library('router');
}
if (!isset($this->CI->url))
{ # Router is not loaded
$this->CI->load->helper('url');
}
$this->CI->load->model('permisos_model');
//$this->CI->load->model('recursos_model'); <- work if enable here

if($this->CI->session->userdata('rolID')){
$this->role_field = $this->CI->session->userdata('rolID');
} else
$this->role_field = 0;
$hola = $this->CI->permisos_model->getAllow();
foreach ($hola->result_array() as $key => $value) {
$this->perms[$value['rolID']][$value['controller']][$value['metod']] = ($value['status'] == 1) ? TRUE : FALSE;
}
}

But it is no longer necessary to state in the controller constructor, what problems or what would help or hurt this situation?
Reply
#5

What is the filename of the models?
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#6

The filename is:
Permisos_model.php
Recursos_model.php
Reply
#7

change this code

$sql = "select * from tab_recursos where idparent =".$parent;
Sercan YANBULOGLU
SEO links REDACTED, per forum policy
Reply
#8

Why do people still use native sql in their queries when we have the query builder class? The only time it is necessary is if you're doing a complex join or something.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply




Theme © iAndrew 2016 - Forum software by © MyBB