Creating Core System Classes
Create a controller file "SP_Controller" in the core folder present in the path folder
application/core.
[php]
class SP_Controller extends CI_Controller {
public function __construct()
{
parent::__construct();
}
}
?>
[/php]
In the above code, it can be understood that SP_Controller is the own version which extends the parent controller CI_Controller.
Then create a Model in the same core folder present in
application/core directory.
[php]
class SP_Model extends CI_Model
{
public function __construct()
{
// Call the CI_Model constructor
parent::__construct();
}
}
?>
[/php]
Using Core System Classes
Now the above created own system classes are used as base system classes in other models and controllers. Create a model
Sample
that extends the class SP_Model.
[php]
<?php
class Sample extends SP_Model
{
public function getModel()
{
echo "<h1>This is Model Function</h1>";
}
}
?>
[/php]
Then create a controller
Sppage that extends the class SP_Controller.
[php]
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Sppage extends SP_Controller {
public function index()
{
$this->load->view('welcome_message');
}
public function spmodel()
{
$this->load->model('Sample'); //calling model
$this->Sample->getModel();
}
}
[/php]
Output: When searched with the url
localhost/Codeigniter/index.php/sppage
the output will be as follows.
To see the output of the created example, enter the url
localhost/Codeigniter/index.php/sppage/spmodel
.