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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程