我如何传递一个视图变量到codeigniter中的控制器? [英] how do i pass a view variable to the controller in codeigniter?

查看:123
本文介绍了我如何传递一个视图变量到codeigniter中的控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图: -

 <html>
<?= link_tag(base_url().'css/simple.css'); ?>
<body>
<?php $this->load->helper('form'); ?>
<?php $this->load->view('commentform'); ?>
<?php $id=$this->uri->segment(3);?>
<?php echo $id;?>
</body>
</html>

我想使用变量 $ id 在我的控制器。我使用codeigniter的方式,和一个初学者。

i would like to use the variable $id in my controller.I'm using codeigniter by the way, and am a beginner. I would appreciate any help on this.

推荐答案

很好,你最好不要这样做。您应该在控制器中首先分配变量,并将它传递给视图,如果你需要使用它。

Well, ideally you wouldn't do it this way. You should assign the variable first in the controller and pass it to the view if you need to use it there.

$data['id'] = $this->uri->segment(3);
$this->load->view('view_file', $data); 

$ id也将在您的视图中可用。

$id would then be available in your view as well.

这篇关于我如何传递一个视图变量到codeigniter中的控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆