[英]Codeigniter “anchor” tag
我是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標簽感到困惑。 還有按鈕
順便說一下,我正在使用引導程序,“ facebox”是一個jquery對話框,因此當我單擊該按鈕時,將出現一個對話框,其中包含有關該用戶的信息。
我希望有人可以幫助我。 非常感謝
echo anchor("useredit.php?emp_id=". $row['emp_id']", "<button type='button' class='btn btn-primary'>Edit</button>", "rel='Facebox'");
另外你有不正確的關閉標簽和TD
從CodeIgniter用戶指南中:
-anchor(uri段,文本,屬性)
-第三個參數可以包含您想要添加到鏈接的屬性列表。 這些屬性可以是簡單的字符串或關聯數組。
因此,您可以執行以下操作:
$args = array("rel"=>"content","target"=>"_blank", "class"=>"your_class");
鏈接: http : //ellislab.com/codeigniter/user-guide/helpers/url_helper.html
為了在CodeIgniter中使用錨點功能,您必須首先通過將URL幫助器添加到自動加載的幫助器列表中或通過放置$this->load->helper('url');
來加載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屬性中的相對鏈接。 第二個是要顯示在錨標記之間的html( '<button type="button" class="btn btn-primary">Edit</button>'
),第三個包含要應用到的其他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()
})
以下是從URL Helper摘錄的一些示例:CodeIgniter用戶指南
這個:
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>';
試試這個...
<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>
由於您是新手,因此請勿在此階段弄亂復雜的功能。
只需像下面這樣放置代碼即可。
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
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.