我是codeigniter框架的新手,我只是想将这个PHP代码转换为Codeigniter版本
echo '<td><a rel="facebox" href=useredit.php?emp_id='. $row['emp_id'] .'><button type="button" class="btn btn-primary">Edit</button></td></a>' ;
我看到了像这样的例子
echo '<td>' . anchor('user/edit_user/'. $i->id, 'edit'). '</td>';
但我对如何添加rel和class标签感到困惑。也是按钮
顺便说一下,我使用bootstrap和&#39; facebox&#39;是一个jquery对话框,所以当我单击该按钮时,将出现一个对话框,其中包含有关该用户的信息。
我希望有人可以帮助我。非常感谢你
答案 0 :(得分:0)
echo anchor("useredit.php?emp_id=". $row['emp_id']", "<button type='button' class='btn btn-primary'>Edit</button>", "rel='Facebox'");
你也有错误的关闭标签和td
答案 1 :(得分:0)
来自CodeIgniter用户指南:
-anchor(uri段,文本,属性)
- 第三个参数可以包含您要添加到链接的属性列表。属性可以是简单的字符串或关联数组。
所以你可以这样做:
$args = array("rel"=>"content","target"=>"_blank", "class"=>"your_class");
链接:http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
答案 2 :(得分:0)
为了在CodeIgniter中使用锚点函数,您必须首先加载URL帮助程序,方法是将其添加到自动加载的帮助程序列表中,或者在调用锚点函数之前将$this->load->helper('url');
放入控制器中。
然后您将使用echo '<td>'.anchor('useredit.php?emp_id='.$row['emp_id'], '<button type="button" class="btn btn-primary">Edit</button>', 'rel="Facebox"').'</td>';
锚函数有3个参数。第一个('useredit.php?emp_id='.$row['emp_id']
)是您通常放在href属性中的相对链接。第二个是要在锚标记('<button type="button" class="btn btn-primary">Edit</button>'
)之间显示的html,第三个包含要应用于锚点的其他html属性,例如id,class或target属性。在您的情况下,您只需要添加'rel="Facebox"'
。
参考http://defunkt.io/facebox/上的Facebox手册,显示您将加载jQuery以及Facebox的css和js,然后在javascript文件中使用以下内容将Facebox附加到链接:
jQuery(document).ready(function($) {
$('a[rel*=facebox]').facebox()
})
答案 3 :(得分:0)
以下是从URL Helper : CodeIgniter User Guide
中提取的一些示例此:
echo anchor('news/local/123', 'My News', 'title="News title"');
会产生:
<a href="http://example.com/index.php/news/local/123" title="News title">My News</a>
而且:
echo anchor('news/local/123', 'My News', array('title' => 'The best news!'));
会产生:
<a href="http://example.com/index.php/news/local/123" title="The best news!">My News</a>
因此,在您的情况下,您可以执行以下操作:
echo '<td>' . anchor('useredit.php?emp_id=' . $row['emp_id'], '<button type="button" class="btn btn-primary">Edit</button>', 'rel="whatever_you_want_here"') . '</td>';
答案 4 :(得分:0)
尝试这个...
<td>
<?php $style='<button type="button" class="btn btn-primary">Edit</button>'; echo anchor('useredit.php?emp_id='.$row['emp_id'],$style,'rel="facebox"');?>
</td>
答案 5 :(得分:-1)
不要在这个阶段搞乱复杂的功能,因为你是新人。
只需将您的代码放在下面。
echo '<td><a rel="facebox" href=user_controller/user_edit/'. $row['emp_id'] .'><button type="button" class="btn btn-primary">Edit</button></td></a>' ;
Class user_controller extends CI_Controller{
function user_edit($userid){
echo $userid;
// you can find the user Id in this way and continue your editing
}
}