PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 12, 2022

[FIXED] Links not relative in cakephp

 January 12, 2022     cakephp, html-helper, hyperlink, php, relative-path     No comments   

Issue

In my layout, I have a menu that I've included as an element, and it contains a link like so.

<? $html->link('New Part Number','/part_numbers/add'); ?>

The problem that I have is that cake isn't redirecting correctly and it ends up sending me to "http://localhost/part_numbers/add" instead of "http://localhost/my_client_folder/client_app/part_numbers/add" (I'm building this locally). My CakePHP app is stored a few directories below my webroot folder, but I thought CakePHP would autodetect how to build the linking no matter where the application was located, right?

So do I need to configure the application root folder, or create a route or something?


Solution

Thank you everyone for your solutions, my previous solution was indeed in error:

You have to build it off of "$this" so that it knows where you're coming from, otherwise it can't figure out how to build a relative link.

Html->link("New Part Number", array('controller' => 'part_numbers', 'action' => 'add')); ?>

The REAL reason that the links were not working, as kindly mentioned below, was because of not specifying the array. This should work to fix the link:

<?= $html->link("New Part Number", array('controller' => 'part_numbers', 'action' => 'add')); ?>


Answered By - Dan
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing