Codeigniter 如何从控制器获取要查看的数据
我在控制器中有函数Codeigniter 如何从控制器获取要查看的数据,codeigniter,Codeigniter,我在控制器中有函数 function test() { $data['lang'] = read_file(APPPATH . "language/bahasa/english.php"); $this->load->view('test', $data); } english.php <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function test() {
$data['lang'] = read_file(APPPATH . "language/bahasa/english.php");
$this->load->view('test', $data);
}
english.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$lang['content.home'] = 'Home';
$lang['content.about_us'] = 'About Us';
$lang['content.team'] = 'Team';
$lang['content.contact'] = 'Contact us';
为什么要编写自己的检索语言文件的方法?有一种方法可以帮你解决这个问题
使用$this->load->view('test',$data)
是将$data
的属性获取到视图中的正确方法。也就是说,如果您的read_file()
用法正常,则视图中的数据将位于$lang['content.home']
等中。我想通过管理面板添加语言,因此我们可以使用管理面板而不是脚本生成新语言。知道吗?这是一个完全不同的问题,你最好分开问。在这种情况下,我想您需要扩展或构建自己的语言类,从数据库中提取语言。