简体   繁体   中英

Codeigniter “anchor” tag

I'm new in codeigniter framework, I just wanna convert this PHP code into Codeigniter version

echo '<td><a rel="facebox" href=useredit.php?emp_id='. $row['emp_id'] .'><button type="button" class="btn btn-primary">Edit</button></td></a>' ;  

I saw an example like this

echo '<td>' . anchor('user/edit_user/'. $i->id, 'edit'). '</td>';

but i'm confused on how can i add the rel and class tag. also the button
by the way i'm using bootstrap and 'facebox' is a jquery dialog box so when i clicked the button a dialog box will appear with the information about that user.

I hope someone might help me. Thank you so much

echo anchor("useredit.php?emp_id=". $row['emp_id']", "<button type='button' class='btn btn-primary'>Edit</button>", "rel='Facebox'");

另外你有不正确的关闭标签和TD

From the CodeIgniter user guide:

-anchor(uri segments, text, attributes)

-The third parameter can contain a list of attributes you would like added to the link. The attributes can be a simple string or an associative array.

So you could do:

$args = array("rel"=>"content","target"=>"_blank", "class"=>"your_class");

Link: http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html

In order to use the anchor function in CodeIgniter, you must first load the URL helper either by adding it to the list of autoloaded helpers or by putting $this->load->helper('url'); in your controller before the anchor function is called.

You would then use echo '<td>'.anchor('useredit.php?emp_id='.$row['emp_id'], '<button type="button" class="btn btn-primary">Edit</button>', 'rel="Facebox"').'</td>';

The anchor function takes 3 arguments. The first ( 'useredit.php?emp_id='.$row['emp_id'] ) is the relative link which you would normally put in the href attribute. The second is the html you want to appear between the anchor tags ( '<button type="button" class="btn btn-primary">Edit</button>' ) and the third contains other html attributes you want to apply to the anchor such as an id, class or target attribute. In your case, you only need to add 'rel="Facebox"' .

Referring to the manual for Facebox at http://defunkt.io/facebox/ shows that you would load jQuery and the css and js for Facebox and then use the following in a javascript file to attach Facebox to the link:

jQuery(document).ready(function($) {
    $('a[rel*=facebox]').facebox() 
})

Here are some examples taken from URL Helper : CodeIgniter User Guide

This:

echo anchor('news/local/123', 'My News', 'title="News title"');

Would produce:

<a href="http://example.com/index.php/news/local/123" title="News title">My News</a>

And this:

echo anchor('news/local/123', 'My News', array('title' => 'The best news!'));

Would produce:

<a href="http://example.com/index.php/news/local/123" title="The best news!">My News</a>

So, in your case, you could do something like:

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>';

try this one...

<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>

Do not mess up with the complex functions in this stage, because you are new.

just place your code like this bellow.

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
      }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM