SteeveDroz
SteeveDroz

Reputation: 6136

CodeIgniter controller that links to an anchor in the middle of the page

I'm trying to have a long page with different sections, with a link that points to each of those.

In my view, I created a page that contains:

<section id="1">
    <h1>One</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</section>
<section id="2">
    <h1>Two</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</section>
<!-- etc. -->

Now, I'd like my controller to link different URLs to different sections.

/page/one => page.php#1
/page/two => page.php#2
etc.

How can I achieve that?

Upvotes: 0

Views: 202

Answers (1)

BEingprabhU
BEingprabhU

Reputation: 1686

You can use redirect function to redirect from one controller to another

redirect('controller_name/function_name#your_section_id','refresh');

If you want to call it as a link then

<a href="<?php echo base_url().'controller_name/function_name#your_section_id'; ?>" >Link name</a>

Hope this can help you.

Upvotes: 2

Related Questions