如何使用语言库中的打印消息从数据库中调用语言ID 在codeigniter中
这是图片:
我要用这段代码实现并以登录形式调用以调用从数据库中选择哪种语言
<div class="form-group valid-form">
<h4><?php echo $this->lang->line('select'); ?></h4>
<select class="form-control" name="language" onchange="javascript:window.location.href='<?php echo base_url(); ?>Language/index/'+this.value;">
<option name="english" value="english" <?php if($this->session->userdata('site_lang') == 'english') echo 'selected="selected"'; ?>>English</option>
<option name="french" value="french" <?php if($this->session->userdata('site_lang') == 'french') echo 'selected="selected"'; ?>>French</option>
</select>
<span class="text-danger"><?php echo form_error("select");?></span>
</div>
答案 0 :(得分:0)
//控制器
function function_name(){
$data=array();
$this->load->model('model_name');
$data['languageArray']=$this->model_name->get_language();
//load view file
$this->load->view('folder/file_name',$data);
}
//型号
function get_language(){
return $this->db->get('table_name')->result_array();
}
//视图
<select class="form-control" name="language_id" id ="language_id">
<option value="">Select Language</option>
<?php foreach ($languageArray as $language) { ?>
<option value="<?php echo $language['id'] ?>">
<?php echo $language['lang'] ?></option>
<?php } ?>
</select>