I am trying to use a third party library for openfire in my Codeigniter Application.
So I have put the libarary in third party folder, and have created an index.php file where I configure my Library.
Then I created a class file in library folder called index.php and I call the third party library like this:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Open extends MY_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
require_once APPPATH.'third_party/openfire/index.php';
}
}
Finally created a controller called user.php and tried to load this libaray using :
$this->load->library('Open');
But on screen this shows me error:
Unable to locate the specified class: Session.php
Its an unexpected error! what can be the possible reasons for this ? If i stop load this library everything works fine.
And I have already loaded Session in autload.php
class Open extends MY_Controller
Try not extending the MY_Controller
Related
I am having a weird issue in which CodeIgniter (3.1) will not load a specific controller. I can load other controllers, but when I create a controller with the name sppb, using any case combination, and save the file as sppb.php it does not load.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Sppb extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
}
}
Above is the entire controller and it is saved to the server with the corresponding name of sppb.php.
I have also taken a different controller that I can load, copied it into a new file, changed the name to sppb, saved it to the server and it still will not load.
This is on a Linux server and I have checked the case in the naming of the file and the Controller.
Your Class file name needs to be 1st letter upper case... like
Sppb.php
The same applies to your class names
class Sppb extends CI_Controller {
My library Class in common/auth/auth_manager.php folder :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Auth_manager {
public function __construct() {
$this->allow_dev_login = TRUE;
$this->_ci =& get_instance();
$this->_ci->load->spark('flexi-auth/1.5.0/');
}}
My controller :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
error_reporting(E_ALL);
class Contacts extends MY_Controller {
public function __construct() {
parent::__construct();
echo "string";
$this->load->library('auth/auth_manager');
}
In the above code the string before loading the library is working . But after loading the page is just blank . Have to use the functions from those libraries . If i use the below code
$this->auth_manager->register();
Getting the error property not defined .
your library file at wrong place
According to Codeigniter standard Keep your library in application/libraries/ directory then you can load library
$this->load->library('auth_manager');
For more follow here
or official docs :- https://ellislab.com/codeigniter/user-guide/general/creating_libraries.html
$this->load->library(); method is finding library in /application/libraries or /system/libraries folders, if you want to load library from another location then register third party folder path
$this->load->add_package_path(APPPATH.'common/auth/');
and then user load library method
$this->load->library('auth_manager');
I have been using codeigniter for sometime now. But I am still new to it. And when I bump into some problem, its takes days to figure it out and solve it.
Unable to locate the model you have specified: page_m
I usullay face these sort of errors too. However since I am using multiple hierarchy of classes (Controllers) I am not being able to figure it out.
Is there any way I could make codeigniter to log the error messages with the line number??
You have to create model in Application/Models directory. and make sure you extend your CI_Model class.
eg. model name : my_model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class my_model extends CI_Model {
public function __construct() {
$this->load->database();
}
}
Are you sure that the file name is the same as the name of the class?
If your file is page_model.php the class must start with class Page_Model extends CI_Model
And in your controller remember $this->load->model('page_model');
I'm developing a web app using codeigniter but I prefer to shy off from handling sessions the codeigniter way due to the bugs it's associated with.Therefore I'm using native php session handling. The problem I'm having is that it seems the session which is started from the default controller doesn't continue in other controllers and it's a pain in the neck.
In both my default controller and the other controllers, I've started or continued the session way on top, before any other code like this:
<?php
#session_start();
So what do I do to make the session continue in the other controllers instead of being confined in the default controller?
As all the controllers get loaded via the main index.php file, you could start the session in there
Create a MY_Controller.php in the core folder with the session start call in its construct - set this to extend CI_Controller and make your other controllers extend your newly created MY_Controller instead.
Something like:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
#session_start();
}
}
/* End of file MY_Controller.php */
/* Location: ./application/core/MY_Controller.php */
Ok, so in my base controller (page.php) I have the following code which works fine:
$this->load->library('Siteclass');
$mysite = new site_model();
The siteclass library references a model named site_model and instantiates based on data received from that model. All is good.
Now I want to load another library so that I can instantiate another object as well. So I add this to page.php:
$this->load->library('Memberclass');
$mysite = new member_model();
But now I get the following error:
Message: Undefined property: Memberclass::$site_model
Filename: libraries/Loader.php
Line Number: 1035
From what I can tell, it seems that the loader class, when being applied to the Memberclass, is somehow still referencing the site_model instead of the member_model. I've checked my code and I am definitely calling the correct files.
Here's what Siteclass.php looks like:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Siteclass extends Controller {
function __construct() {
parent::Controller();
$this->load->model('Site_model');
$data = $this->Site_model->load_site_data();
// etc etc
and here's what Memberclass.php looks like:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Memberclass extends Controller {
function __construct() {
parent::Controller();
$this->load->model('Member_model');
$data = $this->Member_model->load_member_data();
// etc etc
Thanks in advance for any help!
Gary
I think you're confused about how MVC works in CodeIgniter. Why are you using the loader class to create a controller? Why are you creating a stand-alone instance of your model outside of your controller class?
In CodeIgniter, your URLs represent paths to your controllers' methods. That means that your "base controller" should automatically be instantiated if you go to:
www.example.com/memberclass
Or perhaps more to the point, if you have a link like this:
www.example.com/page
You should have a file in your /application/controllers directory called page.php which looks like this:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Page extends Controller {
function __construct() {
parent::Controller();
// etc etc
Furthermore, unless you're loading data from your model to be used every single time you call this controller, you'll want to put your model calls inside a non-constructor method of this class. Something like:
class Page extends Controller {
function __construct() {
parent::Controller();
}
function index() {
$this->load->model('Member_model');
$data = $this->Member_model->load_member_data();
$this->load->view('myview', array('data'=>$data));
}
}
So again...not entirely sure what context you're doing this all in, but it seems like you're not standing firmly within the framework. There's basically no reason you should be using the loader class to load controllers, and furthermore there's no reason you should be creating stand-alone instances of model classes using PHP's new keyword.