Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4605298
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:24:47+00:00 2026-05-22T00:24:47+00:00

I’m using the JsHelper to write JS links to use ajax to load in

  • 0

I’m using the JsHelper to write JS links to use ajax to load in a page. Like this:

<?= $this->Js->link($item['Series']['title'], array(
    'controller' => 'series',
    'action' => 'view',
    $item['Series']['id']
), array('update' => '#menu-items')); ?>

This is working fine, but now I’d like to add it so that you can link to these pages. So, for example, when you click the link it would redirect you to example.com/#!/series/2. You could then also go to this url and the correct page would be loaded in the #menu-items div.

Is this something I’d have to write from scratch, or is there a CakePHP helper or plugin available that would do it for me? I have experience in doing something like this before, but never with CakePHP and unsure where to start.

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:24:47+00:00Added an answer on May 22, 2026 at 12:24 am

    I’ve had a go at tackling it myself now, as I figured that as there was no response then something like this wasn’t already built for CakePHP.

    So first, the javascript:

    var hash = '';
    window.setInterval(function() {
        if(hash != location.hash) {
            hash = location.hash;
    
            if(hash.indexOf('#!/') != -1) {
                var url = hash.substr(2);
    
                $('#my-div').load(url);
            }
        }
    }, 300);
    

    What this does is check to see if the location.hash has changed, if it has, then it checks to see if it starts with #!/. (I.e #!/:controller/:action/:id is the hash that I’m looking for). It then just calls the jQuery load function to load that controller and action.

    I then had to modify my links to use the url method in the HtmlHelper.

    <?
    $hashUrl = $this->Html->url(array(
        'controller' => 'categories',
        'action' => 'view',
        $category['Category']['id']
    ));
    
    echo $this->Html->link($category['Category']['title'], '#!' . $hashUrl);
    ?>
    

    This creates a string for the controller and action, then appends it to #! in the link method. Doing it this way, may seem quite long winded (You could probably write a custom helper to make it one line) but it allows you to change the URLs in the config/routes.php later on. You end up with a url like this: #!/categories/view/2

    Lastly, you need to make sure that in your controllers you have this at the end of each of method you use.

    $this->render('view', 'ajax');
    

    I’m not imagining that this is a perfect solution, but it does the job quite nicely at the moment. Open to suggestions for improvement too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.