搜索结果的Codeigniter链接
我是CodeIgniter的新手,我在显示项目列表时遇到问题,我希望每个项目都是一个链接,因此当用户单击该特定项目时,它将显示该项目的详细信息。或者就我应该用谷歌搜索什么给出一些建议。我真的不知道我应该搜索哪些术语或关键字 控制器:搜索结果的Codeigniter链接,codeigniter,Codeigniter,我是CodeIgniter的新手,我在显示项目列表时遇到问题,我希望每个项目都是一个链接,因此当用户单击该特定项目时,它将显示该项目的详细信息。或者就我应该用谷歌搜索什么给出一些建议。我真的不知道我应该搜索哪些术语或关键字 控制器: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Site extends CI_Controller { public functio
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller
{
public function index()
{
$this->getListOfAgent();
}
function getListOfAgent()
{
$this->load->model("agentDB_model");
$data['results'] = $this->agentDB_model->getAllAgentInfo();
$this->load->view("viewAgent_view", $data);
}
function userInformation()
{
//how to i get the selected item which the user clicked and show the details accordingly?
}
}
版权所有(c)2012 basicsite.com
您需要告诉站点/userInformation
方法您需要哪些记录信息。你用这个
因此,在您看来,更改以下行:
echo "<a href = 'Site/userInformation'>$row->userName</a>";
为了显示信息,OP需要另一个视图页面,他们需要从控制器中的方法
userInformation
加载该视图页面,不是吗?@CrescentMoon-是的,他们需要该方法中的另一个视图向用户口述演示。根据给定的代码,OP知道如何显示视图并向其传递数据。问题是如何获得正确的数据,并将其传递到view.Hmmm,但我们的OP似乎更像是从网络上的某个地方获得了这段代码,并试图理解其背后的基础知识,因为他们已经提到,他们是CI的新手。至于这一点,我高度怀疑他们是否完全理解如何创建视图并向其传递数据。在您的解决方案中再多一点帮助可能会更方便。@CrescentMoon-好的,但这样做的目的不是为OP编写代码,而是回答提出的问题。如果你觉得有必要的话,欢迎你写一个更全面的答案。我可以编辑一下你的答案吗??我不想写代码,只想向OP展示基本结构?可以吗?
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome</title>
</head>
<body>
<div id="content">
<h1>Home Page</h1>
<p>List Of Agent in database</p>
</div>
<?php
foreach($results as $row)
{
echo "<a href = 'Site/userInformation'>$row->userName</a>";
echo "</br>";
echo "</br>";
}
//$this->load->controller(Site/userInformation);
?>
<div id="footer">
<p>Copyright (c) 2012 basicsite.com</p>
</div>
</body>
</html>
echo "<a href = 'Site/userInformation'>$row->userName</a>";
echo "<a href = 'Site/userInformation/$row->userID'>$row->userName</a>";
function userInformation($userID)
{
// now, you use the model to get the correct record from the db based on
// the $userID and display the information
}