My View :-
<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>
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.
in my view i add link
in my link.php controler i add function show_id
in my next view daftarmember_form.html
)
they print mantap,
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 www.mysite.com/thecontrollername/thefunction/id
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: www.mysite.com/home/show_id/id
your function in home will read the id"
in your home controller:
in the view (show_id_view):
nothing else..
hope this helps.
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.
$id would then be available in your view as well.