How to define a global variable(value) in codeIgniter

user3077503

I simply do not mean how to define a global variable/constant in CodeIgniter. Let me explain: I have made a theme engine which is select-able from the current logged in user's control panel. This engine is not very complicated, but a simple folder. anyway, what I do across the application, is that I write one line of code to get the current theme selected by the user. I use a one line of code to get the name, and then store it in a variable:

$theme_name = $this->theme->get_theme_with_slash(false);

And then, I user $theme_name like this to get the proper view:

$this->load->view($theme_name.'result', $data);

And in all of my controllers that loads view I should repeat this process. What I need, is to call the function which gets the theme_name and store in the variable and then use the variable/session/function across the application. My approach currently is the helper's function which is a little less convenient compared to session/variable.

tomexsans

Create A core controller, since your process requires logical operations then you need a method for that.

application/core/MY_Controller.php

class MY_Controller Extends CI_Controller
{

   protected $default_theme = 'theme';

   public function __construct()
   {
      parent::__construct();
   }

   public function get_theme()
   {
         //your code for selecting the current theme selected from
         //the database
         $theme_from_db = '';

         return $theme_from_db == NULL ? $this->default_theme : $theme_from_db;
   }
}

Your Controller must extend MY_Controller

application/controller/view.php

class view extends MY_Controller
{
   public function index()
   {
     $this->load->view($this->get_theme().'result', $data);
   }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to define Global variable in codeigniter?

From Dev

How to define a global function in scala?

From Dev

How to define global function in Python?

From Dev

How to define global variable for Twig

From Dev

How to define a global array in python

From Dev

How to define global parameters in OpenAPI?

From Dev

How to define a global function in scala?

From Dev

How Define Some Variables in Codeigniter

From Dev

Possible to define custom form validation callbacks in the global scope in CodeIgniter

From Dev

How to define a global counter in golang http server

From Dev

How can I define global variables in nunjucks?

From Java

How to define global launch configuration in VSCode

From Dev

How can I define a global property in rhino?

From Dev

How to define global variable inside a function?

From Dev

How to define Global variable outside class?

From Dev

How to define and use global array in Haskell?

From Dev

How to define a global read\write variables in Spark

From Dev

How to define a global variable in LLVM and use it in C?

From Dev

How to define global variable in PL/SQL in Oracle?

From Dev

C - How to define a global variable using a loop?

From Dev

How to define global variable inside a function?

From Dev

How to define Preprocessor Directive Global in c#

From Dev

How can I define global variables in nunjucks?

From Dev

How to define global template variable in AngularDart

From Dev

How to define an array with global scope in SilverStripe?

From Dev

[Talend]How to define a global filed in a talend job

From Dev

how to define a global variable inside linux kernel?

From Dev

How to use global variable in PHP Codeigniter

From Dev

Request.Querystring(variablevalue) possible?

Related Related

  1. 1

    how to define Global variable in codeigniter?

  2. 2

    How to define a global function in scala?

  3. 3

    How to define global function in Python?

  4. 4

    How to define global variable for Twig

  5. 5

    How to define a global array in python

  6. 6

    How to define global parameters in OpenAPI?

  7. 7

    How to define a global function in scala?

  8. 8

    How Define Some Variables in Codeigniter

  9. 9

    Possible to define custom form validation callbacks in the global scope in CodeIgniter

  10. 10

    How to define a global counter in golang http server

  11. 11

    How can I define global variables in nunjucks?

  12. 12

    How to define global launch configuration in VSCode

  13. 13

    How can I define a global property in rhino?

  14. 14

    How to define global variable inside a function?

  15. 15

    How to define Global variable outside class?

  16. 16

    How to define and use global array in Haskell?

  17. 17

    How to define a global read\write variables in Spark

  18. 18

    How to define a global variable in LLVM and use it in C?

  19. 19

    How to define global variable in PL/SQL in Oracle?

  20. 20

    C - How to define a global variable using a loop?

  21. 21

    How to define global variable inside a function?

  22. 22

    How to define Preprocessor Directive Global in c#

  23. 23

    How can I define global variables in nunjucks?

  24. 24

    How to define global template variable in AngularDart

  25. 25

    How to define an array with global scope in SilverStripe?

  26. 26

    [Talend]How to define a global filed in a talend job

  27. 27

    how to define a global variable inside linux kernel?

  28. 28

    How to use global variable in PHP Codeigniter

  29. 29

    Request.Querystring(variablevalue) possible?

HotTag

Archive