How can the template variables of the PHP framework be used globally?

I want some template variables to be available globally, such as some system setup information and website title classes, and different modules may need to call the same variables. how can such variables be used globally?

now I"ve done a simple test with TP5 and found that cross-controller or method doesn"t work. I hope you can help me sort out the logic and describe the specific implementation ideas. Thank you in advance. A rookie asks for help.

create a base class, or a public module?

Mar.05,2021

in fact, many places are global.

config.php can define a custom file, which is introduced in config.php, and you can use config to get it in the template.

The

common.php file is also global. The code inside can be very free.

index.php can also be implemented.

most business developers implement a common controller, but ok is fine at this level.

if you are not satisfied, you can take a look at the thinkphp life cycle described in the document.


configuration files under the application


set an option called template variable in your configuration file called config

clipboard.png

you can customize a variable in it!


can be configured in params-local.php under the config directory, and you can use Yii::$app- > params to get the configured variable value.


TP5 has been called globally in many places. The upstairs is quite complete. To add, if you are a developer background, define it in AdminController, and then all controller inheriting this class can also be used. The


view component has a params property, which is global in the view.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2ba6d-2affa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2ba6d-2affa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?