2011-06-26 12:46
浏览 64


My View :-

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

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.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongzouche9108 2011-06-26 12:48

    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 would then be available in your view as well.

    解决 无用
    打赏 举报
  • dqe9657 2011-06-26 15:50

    you should not call the $id from the View, you should get it at the controller level and pass it to the View.

    as Bulk said. you URL will be something like that

    for example your controller if home and there is a show_id function in it and your view is call show_id_view.php.

    you will have your url like this:

    your function in home will read the id"

    in your home controller:

    function show_id(){
    $view_data['id'] = $id;

    in the view (show_id_view):

    <?php echo $id ?>

    nothing else..

    hope this helps.

    解决 无用
    打赏 举报
  • duankao4489 2014-04-02 15:13

    in my view i add link

     <li><a href="<?php echo base_url()?>link/show_id/mantap"> coba </li> 

    in my link.php controler i add function show_id

    function show_id(){
            $data['coba'] = $id;

    in my next view daftarmember_form.html


    <?php echo $id;?>

    they print mantap,

    解决 无用
    打赏 举报

相关推荐 更多相似问题