2012-04-21 21:53
浏览 57


Using CodeIgniter I am trying to create a link that the user can click within a view to show them the details of a record in my database.

In ASP.NET MVC3 with C# I would do it with @Html.ActionLink("Controller", "Action", new { id = item.Id})

This is my session controllers index() function

public function index()
        $data['sessions'] = $this->session_model->get_sessions();

        $this->load->view('session/index', $data);

This is the index view it loads where I want to be able to click the link to go to enter() function


<th>Session Name</th>

<?php foreach ($sessions as $session_item): ?>
        <td> <?php echo $session_item['sessionName'] ?> </td>
        <td> <?php echo $session_item['sessionDesc'] ?> </td>
        <td> <?php echo $session_item['adminName'] ?> </td>
        <td> <a id="enterSession" href=<?php echo site_url("session/enter" + $session_item['id']) ?> >Enter</a></td>

<?php endforeach ?>

The enter session points me to the url "" (if the id of my item is 1) whereas I expect ""

Any ideas on how I can make it call the enter() function also in the session controller (shown below)

 public function enter($id) {

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzhan1963
    douzhan1963 2012-04-21 22:15

    There seems to be a typo in the string concatenation in your PHP code. Perhaps it will work to use:

    site_url("session/enter" . $session_item['id'])

    ... rather than a + sign between the two strings.

    Regarding the second question - it looks correct as-is. Is it failing to call the session controller's enter() function passing the $id as an argument (assuming the URL is correct)?.

    点赞 评论