doucang5542 2012-04-10 21:17
浏览 20
已采纳

如何在codeigniter中创建设置功能?

I have created a MY_Controller and I'm linking to it through my main controller... I am now trying to create a settings function which will get all the results from a database and return the one you want... The only problem I'm having is being able to do using the template engine...

protected function settings()
{
    // select all settings from database
    $query = $this->db->query('SELECT * FROM settings');

    // get result from database
    $this->data['settings'] = $query->result_array();

    // return array of data
    return $this->data['settings'];
}

How can i go about this?

The only way I can access it at the moment is:

{settings}
    {name}
    {value}
{/settings}

P.S. I call the function $this->settings() in the __construct() function also I forgot to mention I'm using codeigniter

  • 写回答

1条回答 默认 最新

  • drqn5418 2012-04-10 21:59
    关注

    Controller code:

    $data['settings'] = $this->settings();
    $this->load->view('whatever_your_view_file_is_named', $data);
    

    Now in your view the setting properties will be available as members of an object named settings as that was the key you set in the data array you pass to the view.

    View code:

    echo $settings->name;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵