dqp4933 2012-05-08 20:33
浏览 45
已采纳

kohana:包含字符串的文件?

I am new to kohana and not an expert with php excuse me if this is a duplicate but I don't even know the correct terms to perform a search for this.

I want to have a file where I can have a list of key-value thing and I want these to be accessible from templates and/or controllers.

in order to do this: 1) what do I need to do to create such a file? which folder do I put it in? what will make it accessible by template files and controllers?

2) shall I declare each key as a $string and assign a value i.e. $example = "example value"; or is there a better way?

thank you

  • 写回答

1条回答 默认 最新

  • douyuanliao8815 2012-05-08 22:22
    关注

    Sounds like you want to store some data in a config file. You can learn how to use config files here: http://kohanaframework.org/3.2/guide/kohana/files/config

    Config data can be read mostly anywhere in your application using the global Kohana class, eg: Kohana::$config->load('myconf'); but generally you don't want to access globals in your views, but rather pass in data to your views, eg:

    class Controller_Contact extends Controller {
    
            public function action_index()
            {    
                    $names = Kohana::$config->load('names');
    
                    $view = View::factory('people')
                            ->set('names', $names);
    
                    $this->response->body($view);
            }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了