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 9218051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:46:25+00:00 2026-06-18T02:46:25+00:00

I dislike the Html->link() method. I appreciate it, but it uglies up the code

  • 0

I dislike the Html->link() method. I appreciate it, but it uglies up the code and I don’t believe that something so basic should require a method. However, in my project, I find I must use it if I want to have proper URLs. I’ll accept that, but I want to know that I have to before continuing making links in this (large) project.

I’ve attempted to find some ways to get the cakeURL in a view. Nothing worked out.

My goal is to go from this:

<?=$this->Html->link('quality view', array('controller' => 'quals', 'action' => 'show')); ?>

To this:

<a href="<?=URL.'quals/show'?>">

But I cannot write or find a way to get such a constant working if I change the page’s URL. (even something such as visiting /quals/ and /quals will show different URLs)

  • 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-06-18T02:46:27+00:00Added an answer on June 18, 2026 at 2:46 am

    I also dislike the link method, I find it overkill for adding attributes like class, id and target=”_blank” to my links.

    I do this for links:

    <a class="myclass" href="<?php echo $this->Html->url(array('controller'=>'my_controller','action'=>'my_action','plugin'=>false)); ?>">My Anchor Text</a>
    

    So, I still use the HTML helper to get the URL, but the html element I code myself. I would recommend doing it that way, rather than hard-coding the URLs. This is the Cake way to do it, and it allows you to take full advantage of Cake’s inbuilt routing functionality in routes.php, and create pretty routes without having to hard-code or remember them in more than one place.

    It also makes it easier for others looking at your code in future – eg. does the hard-coded ‘quals/show’ link refer to the quals/show directory in your webroot? Or does it refer to the show action of the quals controller? (and it only gets more complex when you start working with plugins). If you use the html helper to create URL’s, all that stuff is immediately clear.

    If you want to make it look tidy, you could break it into two lines like this:

    <?php $url = $this->Html->url(array('controller'=>'my_controller','action'=>'my_action','plugin'=>false)); ?>
    <a class="myclass" href="<?php echo $url; ?>" >My Anchor Text</a>
    

    If you’ve got a large project, it’s even more reason to use Cake’s helpers for URLs. It may seem like a good idea now, but hard coding them will give you a big headache at some point in the future.

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

Sidebar

Related Questions

I confess at the outset that I dislike and don't really understand regex properly.
I love notepad++ but I dislike when someone sends me an .html or .xml
It seems like there should be a better way to code this: HTML snippet:
i have this bit of html. (Link at bottom) Its output of php code
So I am loading an html page with a basic script and a basic
I dislike having magic boxes scattered all over my code...how exactly do these two
As that web-standards geek I am, I dislike the default <form runat=server> that surrounds
IDEs are wonderful for many things. But I dislike how they make me use
I might be in the minority, but I really dislike how the Subversion client
I work with C# at work but dislike how with webforms it spews out

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.