Library inside library - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Library inside library (/showthread.php?tid=5160) Pages:
1
2
|
Library inside library - El Forum - 01-09-2008 [eluser]Sawariya[/eluser] Hi Friends How can call a library class in anothor library.. i created two libraries i have one library name abcd and abcd is bcd class CI_abcd { var $obj; function CI_abcd () { $this->obj =& get_instance(); $this->obj->load->library('ua_abcd '); log_message('debug', 'User Authentication Class Initialised via '.get_class($this->obj)); } } this is correct way to call ?? Library inside library - El Forum - 01-09-2008 [eluser]xwero[/eluser] Yes. A library where you use the get_instance function isn't that much different from a model or controller. Library inside library - El Forum - 01-09-2008 [eluser]Sawariya[/eluser] but i am getting this error.. A PHP Error was encountered Severity: Notice Message: Undefined property: Front::$authorize Filename: controllers/front.php Line Number: 44 Fatal error: Call to a member function roleCheck() on a non-object in E:\xampp\htdocs\userauth\system\application\controllers\front.php on line 44 Library inside library - El Forum - 01-09-2008 [eluser]Sawariya[/eluser] Anybody can help me Library inside library - El Forum - 01-09-2008 [eluser]tonanbarbarian[/eluser] you will have to give more information post the code of the controller and if possible the library that is being loaded one tip is to make sure that library files are named correctly. recommended is the first character of the name is in uppercase and the rest in lower i.e. libraries/Auth.php and when you load the library you can use either upper or lower case for the name, but the name of the object created will always be all lower case Code: $this->load->library('Auth'); I also noticed from your previous example that you were calling your class CI_abc or similar. Do not... Only core CI classes are prefixed with CI You should just call it abc or whatever i.e. Code: class Auth { Library inside library - El Forum - 01-09-2008 [eluser]Sawariya[/eluser] Thanks for your reply ... i have already tried this .. but its not working... any other solution from your side??? Library inside library - El Forum - 01-09-2008 [eluser]Sawariya[/eluser] one library is---Userauth class CI_Userauth { var $obj; function CI_Userauth() { $this->obj =& get_instance(); $this->obj->load->model('user_group_model', '', TRUE); $this->obj->load->model('remember_me', '', TRUE); $this->obj->load->library('ua_authorize'); log_message('debug', 'User Authentication Class Initialised via '.get_class($this->obj)); } } another one is class Ua_authorize { // ACL variables var $allowed_users = array(); // Allowed Groups and users var $denied_users = array(); // Denied Groups and users var $allowed_set = FALSE; // Has set_allowed() been used var $denied_set = FALSE; // Has set_denied() been used var $allow = FALSE; // Cuurent status of permission function Ua_authorize() { $this->obj =& get_instance(); } } Library inside library - El Forum - 01-09-2008 [eluser]tonanbarbarian[/eluser] I do not see the method roleCheck nor the place where it is called in the code you have provided please be a bit more complete with the code if you can show the full code and indicate where exactly the error is occuring maybe we can help Library inside library - El Forum - 01-09-2008 [eluser]xwero[/eluser] I guess both files are in the libraries directory? and you call the roleCheck method like this Code: $this->obj->ua_authorize->roleCheck(); Library inside library - El Forum - 01-09-2008 [eluser]Sawariya[/eluser] Thanks for your reply here is library.. <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Ua_authorize { var $allowed_users = array(); // Allowed Groups and users var $denied_users = array(); // Denied Groups and users var $allowed_set = FALSE; // Has set_allowed() been used var $denied_set = FALSE; // Has set_denied() been used var $allow = FALSE; // Cuurent status of permission function Ua_authorize() { $this->obj =& get_instance(); } function roleCheck($role = 'guest', $uri = '') { If ( $role != 'guest' ) { $list = 'ua_role_'.$role.'_allow'; $list = $this->obj->config->item($list); if( !empty($list) ) { $this->set_allow($list); } $list = 'ua_role_'.$role.'_deny'; $list = $this->obj->config->item($list); if( !empty($list) ) { $this->set_deny($list); } } $this->obj->session->set_flashdata('uri', $uri); log_message('debug','roleCheck: Role = '.$role); if(!$this->obj->userauth->check('', TRUE)) { redirect('user/auth_error'); } } |