The use of tp5.0 behavior, can be stored in JSON data, easy to read data.

Source: Internet
Author: User

1. First create a new folder named behavior;
2. Create a new class under the folder, such as the Auth class;
3. Define namespaces
<?php
namespace App\admin\behavior;
Config is stored in JSON configuration data, which is introduced into the model for easy data reading.
Use App\admin\model\config;
The introduction of this is to facilitate the use of prompt methods such as: $this->success (); $this->success ();
Use \traits\controller\jump;
Class auth{
Public Function run () {
$model = Config::find (1);
$data = $model->content;
$data =json_decode ($data, true);
Defined
Config (' ctitle ', $data [' ctitle ']);
Config (' words ', $data [' words ']);
Config (' descript ', $data [' descript ']);
Config (' number ', $data [' number ']);
Config (' phone ', $data [' phone ']);
Config (' address ', $data [' address ']);

}

}
3. In the tag.php file under Application
' App_init ' = [

      ‘app\admin\behavior\Auth‘]    //引入这个类    4.在页面模板调用的时候{:config(‘ctitle‘)};可以在页面上显示把json中的数据读取出来。    这是我的个人理解,有什么不对的地方请多指教。

The use of tp5.0 behavior, can be stored in JSON data, easy to read data.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.