hi..I am wanted to use the anchor() tag which is one of the url helper in codeigniter for the div.

Below is the code which i want to convert into the codeigniter form :

<a href="events/page/<?php echo $id; ?>">
   <div class="title_row" id="<?php echo $id; ?>">
       <div class="content" >
         <div class="data">
       </div>
       </div><!--content ends here-->
       <input type="hidden" value="<?php echo $id; ?>" class="datahtml"/>
   </div><!--title row ends here-->
</a>

the question again is how could i change the normal <a href=""> into the codeigniter anchor() form?


please help, my search on google returns no results :(

Thank You :)

Dani AI

Generated

You can pass any HTML as the second parameter to anchor(), and use the third parameter to set attributes on the <a> itself. That lets you generate a block-level, fully clickable container without keeping a separate <div> wrapper. Also, avoid placing an <input> inside an anchor; interactive content inside <a> is invalid HTML and can break accessibility. Instead, carry the ID in an attribute like data-id.

Example:

<?php
// In your controller or view
$this->load->helper('url'); // or autoload it

$id  = (int) $id;
$url = 'events/page/' . $id;

echo anchor(
    $url,
    '<div class="content"><div class="data"></div></div>',
    array(
        'class'   => 'title_row',
        'id'      => 'row-' . $id,
        'data-id' => $id
    )
);

This outputs a full <a> tag wrapping your inner markup. Style the anchor as a block to behave like your original container (e.g., .title_row { display:block; }). If you do not need nested <div>s, you can move classes/IDs directly onto the <a> and keep the inner HTML minimal.

Note: Wrapping block elements inside anchors is fine in HTML5, but keep other interactive elements out. See the permitted content guidance for the anchor element on MDN at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.