简体   繁体   中英

codeigniter 3.11 global variable array in constants.php

How can i declare a global array in constants.php?

I want use an array of this form in a helper file.

$process['up_position']['Title']='Up position';
$process['up_position']['icon']='icon-up';
$process['up_position']['description']='Up a position';

$process['down_position']['Title']='Down position';
$process['down_position']['icon']='icon-down';
$process['down_position']['description']='Down a position';

What is the better way?

Thank you!!

I see constants.php but all constants are simple values

Constants are simple values in general. These are values that never change. My own opinion is

  1. Option 1: to have these in the Config file if they are system wide settings.
  2. Option 2: to have them in a table if you ever want to change them.
  3. Option 3: to have them in the super class of your Controller or Model so you have them inherited in every file you create, you don't need to assign them anymore but just use them as they are.
  4. Option 4: to have them in a library.

It all depends where you read / use them from. I see you have "title", "icon" and "description" so these seem to be objects used in a view, I'd assume. Then you can create a controller super class where objects like that are created, you just assign the values to them once you call the view and the view will have the values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM