• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic question: how to pass unique identifier with anchor()

Hi everyone,

This a very basic concept, but I've never put together a website before so I've never thought about if before. I am working on the portfolio page of a website. On it there are 2 'summaries' of 2 separate items:

<div class="span4">
          <h2>Heading1</h2> // item1
           <p>text1 </p>
          <p><a class="btn" href="#">View details »</a></p>
        <div class="span4">
          <h2>Heading2</h2> // item2
          <p><a class="btn" href="#">View details »</a></p>

When I click on the button I want to go to a template page and dynamically fill in a more detailed discussion of each Item. But there has to be a way to uniquely identify item 1 and item 2 so I know which db record to use to populate the template.

using the anchor function I can do:

?php echo anchor('template_controller', 'Learn More »', 'class="btn"');

but how do I pass a unique identifier to the template controller?

Thank you,


The syntax for anchor tag in CI is anchor(uri segments, text, attributes). What ever you pass to the controller can be extracted in the controller method using the syntax $this->uri->segment(n, 'somedefaultvalue'); So, your 'n' will be 3 (we are counting example.com as 0, next as 1 etc) if you had this format for the first argument of anchor(), http://example.com/class/function/ID.

Thank You

&lt;?php echo anchor('template_controller/'.$id, 'Learn More »', 'class="btn"'); ?&gt;

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.