doupu7651
2012-04-21 21:53
浏览 62
已采纳

使用View中的参数链接到Controller函数(CodeIgniter)

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('_header');
        $this->load->view('session/index', $data);
        $this->load->view('_footer');
}

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

<table>

<th>Session Name</th>
<th>Description</th>
<th>Host</th>
<th></th>

<?php foreach ($sessions as $session_item): ?>
    <tr>
        <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>

    </tr>
<?php endforeach ?>

The enter session points me to the url "http://192.168.1.36/index.php/1" (if the id of my item is 1) whereas I expect "http://192.168.1.36/index.php/session/enter/1"

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

 public function enter($id) {

        $this->load->view('_header');
        $this->load->view('session/enter');
        $this->load->view('_footer');
    }

图片转代码服务由CSDN问答提供 功能建议

使用CodeIgniter我正在尝试创建一个链接,用户可以在视图中单击该链接以向其显示详细信息 记录在我的数据库中。</ p>

在使用C#的ASP.NET MVC3中,我将使用 @ Html.ActionLink(“Controller”,“Action”,new {id = item。 Id})</ code> </ p>

这是我的会话控制器index()函数</ p>

 公共函数索引()
 
 \  n $ data ['sessions'] = $ this-&gt; session_model-&gt; get_sessions(); 
 
 $ this-&gt; load-&gt; view('_ header'); 
 $ this-&gt; load  - &gt; view('session / index',$ data); 
 $ this-&gt; load-&gt; view('_ footer'); 
} 
 </ code> </ pre> 
 
  

这是它加载的索引视图,我希望能够点击链接转到enter()函数</ p>

 &lt; table&gt; 
 
&lt;  th&gt;会话名称&lt; / th&gt; 
&lt; th&gt;描述&lt; / th&gt; 
&lt; th&gt;主机&lt; / th&gt; 
&lt; th&gt;&lt; / th&gt; 
 
&lt;?php foreach($ sessions as  $ session_item):?&gt; 
&lt; tr&gt; 
  &LT; TD&GT;  &lt;?php echo $ session_item ['sessionName']?&gt;  &lt; / td&gt; 
&lt; td&gt;  &lt;?php echo $ session_item ['sessionDesc']?&gt;  &lt; / td&gt; 
&lt; td&gt;  &lt;?php echo $ session_item ['adminName']?&gt;  &lt; / td&gt; 
&lt; td&gt;  &lt; a id =“enterSession”href =&lt;?php echo site_url(“session / enter”+ $ session_item ['id'])?&gt;  &gt;输入&lt; / a&gt;&lt; / td&gt; 
 
&lt; / tr&gt; 
&lt;?php endforeach?&gt; 
 </ code> </ pre> 
 
 

</ p >

输入会话将我指向网址“http://192.168.1.36/index.php/1”(如果我的项目的ID为1),我希望“http://192.168 .1.36 / index.php / session / enter / 1“</ p>

关于如何在会话控制器中调用enter()函数的任何想法(如下所示)</ p >

 公共函数输入($ id){
 
 $ this-&gt; load-&gt; view('_ header'); 
 $ this-&gt; load-&gt;  view('session / enter'); 
 $ this-&gt; load-&gt; view('_ footer'); 
} 
 </ code> </ pre> 
 </ div>

1条回答 默认 最新

相关推荐 更多相似问题