I have a CodeIgniter spark defining&autoloading a class libraries/Nci_nicecontroller.php:
class Nci_nicecontroller extends CI_Controller {
//...
}
//autoloaded using $autoload['libraries'][]='nci_nicecontroller';
now I want to use Nci_nicecontroller in my application's controller, e.g.:
class Welcome extends Nci_nicecontroller {
//...
}
//autoloaded using $autoload['sparks'][]='nci-extensions/0.0.4';
obviously, I can't just $this->load->spark in my controller's constructor, because it's required on class extension.
when not using sparks, I just put the Nci_nicecontroller in a core/MY_Controller.php, but with sparks, this won't work.
I tried autoloading the spark in my application, which didn't work.
Then I tried:
get_instance()->load->spark('nci-extensions/0.0.4');
in the header of controllers/welcome.php, which gives me following errors:
Severity: Notice
Message: Trying to get property of non-object
Filename: controllers/welcome.php
Line Number: 2
--and--
Fatal error: Call to a member function spark() on a non-object in
C:\xampp\htdocs\CodeIgniter_demo\application\controllers\welcome.php on line 2
what shall I do?
Try to do something like that:
class Wellcome extends CI_Controller {
protected static $_nci = null;
public function __construct(){
parent::__construct();
$this->_nci = $this->load->spark('nci-extensions/0.0.4');
}
public function index(){
$result = $this->_nci->getSomething();
echo $result;
}
}
Related
modules
--customers
----controllers
-------customers.php
----models
-------customers_model.php
-------handler_model.php
Hi im trying to load two models in my controllers by using this:
class Customers extends CoreAPI
{
public function __construct()
{
parent :: __construct();
$this->load->model('Customers_model', 'Customers');
$this->load->model('Customers/Handler_model');
}
public function test_get()
{
$this->Handler_model->test;
exit;
}
However, I always get this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI::$test
Filename: core/Model.php
Line Number: 73
I tried the two different ways of loading a model as stated.
Folder Structure
Please help. Thank you.
class Handler_model extends CI_Model
{
public function __construct()
{
parent :: __construct();
}
public function test()
{
echo 'TEST';
}
}
I am a newbie to Codeigniter and trying to build a service registration page. Not just the page but the whole website has this error.
$autoload['model'] = array('User_model','Material_model');
$autoload['libraries'] = array('database','form_validation');
class services extends CI_Controller {
public function service1()
{
$this->form_validation->set_rules('type','Type',trim|required);
$this->form_validation->set_rules('area','Area',trim|required);
$this->form_validation->set_rules('quantity','Quantity',trim|required);
$this->form_validation->set_rules('details','Details',trim|required);
$this->form_validation->set_rules('name','Name',trim|required);
$this->form_validation->set_rules('number','Number',trim|required);
$this->form_validation->set_rules('location','Location',trim|required);
if($this->form_validation->run()==FALSE){
$data['main_view']="page_view";
$this->load->view('layouts/main',$data);
} else{
$this->user_model->create_user();
redirect('/');
}
I'm getting this error in user model from material model. Th
Actually, you should load the model in your parent construct.
For example:
class services extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->model('your_directory_model, 'your_initialize_model');
}
}
And then, if you want to use your model. you can build code like i write below in your method.
$this->your_initialize_model->your_model_method();
controller
public function add_package()
{
$this->load->model('admin_model');
$this->Admin_model->add_packages($package);
}
admin_model.php
class Admin_model extends CI_Model
{
public function add_packages($data)
{
return $this->db->insert('george_packges',$data);
}
}
Why i will getting this error Undefined property: Admin::$Admin_model and also this
fatal error: Call to a member function add_packages() on null in
C:\xampp\htdocs\holiday\application\controllers\Admin.php on line 130
Change the loading model variable as the model loaded and used was different so the variable was not matching.
$this->Admin_model->add_packages($package);//currently used
$this->admin_model->add_packages($package);
I am new to codeigniter and I was trying my first app from the reference of this link
But I got the following error:
Fatal error: Class 'Controller' not found in /var/www/CodeIgniter/application/controllers/helloworld.php on line 2
Thi should be done like this
Class Mycontroller Extends CI_Controller
{
function __construct(){
parent::__construct();
}
//other functions
}
Class Mymodel Extends CI_Model
{
function __construct(){
parent::__construct();
}
//other functions
}
I'm trying to work with the CI framework (PHP), and not having much luck with the core "Input" class.
Here's my code:
$user_name = $this->input->post('username');
$password = $this->input->post('password');
This is the result when I try to load the controller:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Login::$input
Filename: controllers/login.php
Line Number: 24
Any Tips?
Make sure that your controller extends CI_Controller and that you call the parent constructor in your own:
class Login extends CI_Controller {
public function __construct() {
parent::__construct();
}
/* the rest of your code... */
}