Answer the question
In order to leave comments, you need to log in
How to take some functions from controllers to a higher level?
Good afternoon
I comprehend CODEIGNITER
There are some functions that are used in any section of the site ...
T e - these functions need direct access from any controller
How to implement it correctly?
I did this: (but I feel that this is not the right approach)
in routes:
further
Main.php itself$route['default_controller'] = 'main';
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once('Base.php');
class Main extends Base {
public function __construct(){
parent::__construct();
}
<?php
class Base extends CI_Controller{
public function __construct(){
parent::__construct();
}
}
Answer the question
In order to leave comments, you need to log in
Make Helper (if the methods are not related to the controller functionality), otherwise, customize the parent controller, and inherit yours from it.
If you use these functions in controllers, this is correct.
If you use these functions in templates, then it is logical to make helpers.
For such lazy cases, I made a model, stuck it into autoload. And then I call anywhere in the template or controller.
Like <?=$this->mymodel->get_url_logo()?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question