Reputation: 129
I am trying to pass the page id through the url Here is my code,problem is i will not get the required page id to the page only get the path . Please help. View Page
<li>
<a href="view/page_id=$page_id"><i class="fa fa-table fa-fw"></i>Hotel 1</a>
</li>
<li>
<a href="view1/page_id=$page_id"><i class="fa fa-table fa-fw"></i>Hotel 2</a>
</li>
Controller Page
public function view()
{
echo $page_id =$this->uri->segment(1);
$this->load->helper('url');
$data['offers_name'] = $this->Login_set->get_offer($id);
$data['offers_description'] = $data['offers_name']['offers_description'];
$this->load->view('App_stay/pages/hotel1_offers.php');
}
public function view1()
{
echo $page_id =$this->uri->segment(2);
$this->load->helper('url');
$data['offers_name'] = $this->Login_set->get_offer($id);
$data['offers_description'] = $data['offers_name']['offers_description'];
$this->load->view('App_stay/pages/hotel2_offers.php');
}
Upvotes: 0
Views: 10395
Reputation: 342
Change this:
<li>
<a href="view/page_id=$page_id"><i class="fa fa-table fa-fw"></i>Hotel 1</a>
</li>
<li>
<a href="view1/page_id=$page_id"><i class="fa fa-table fa-fw"></i>Hotel 2</a>
</li>
into this:
<li>
<a href="view/<?php echo $page_id ?>"><i class="fa fa-table fa-fw"></i>Hotel 1</a>
</li>
<li>
<a href="view1/<?php echo $page_id ?>"><i class="fa fa-table fa-fw"></i>Hotel 2</a>
</li>
Add $this->uri->segment('segment_number')
in your controller to get the value from url
public function view()
{
$page_id =$this->uri->segment(3);
$data['offers_name'] = $this->Login_set->get_offer($id);
$data['offers_description'] = $data['offers_name']['offers_description'];
$this->load->view('App_stay/pages/hotel1_offers.php');
//I put your codes here because you want Spoon Feed
}
public function view1()
{
$page_id =$this->uri->segment(3);
...//rest of your codes here
}
Upvotes: 1
Reputation: 1864
You can pass as url parameter
<li>
<a href="view/$page_id"><i class="fa fa-table fa-fw"></i>Hotel 1</a>
</li>
And can access like this in controller
public function view($page_id)
{
echo $page_id;
}
you can load helper in controller constructor
function __construct() {
$this->load->helper('url');
}
Upvotes: 1