Jump to content


Photo

CakePHP routing

cake php routing error

Best Answer 244863, 27 February 2013 - 12:09 PM

added:

 

/index.php/

 

before the URL and it worked fine!!

 

thanks,

Go to the full post


  • Please log in to reply
6 replies to this topic

#1 244863

244863

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationGloucester
  • Age:26

Posted 27 February 2013 - 10:52 AM

Hi,

 

when I am on a page, with a URL like:

 

http://localhost/index.php/users/index

 

and I have a HTML <a> tag with a href of "users/add"

 

when I click on the link it takes me to the following URL:

 

http://localhost/index.php/users/users/add

 

it does not remove the controller name???

 

BUT when I am on:

 

http://localhost/index.php/users/

 

it goes to the right URL:

 

http://localhost/index.php/users/add

 

any ideas welcome.


Iain Rose (BSc)
Software Design & Development Engineer
365 On-Demand Solutions


#2 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 27 February 2013 - 11:41 AM

Try putting a / in front of users.

Or post your code so we can see. I've used the CakePHP link() function and never had that problem.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#3 244863

244863

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationGloucester
  • Age:26

Posted 27 February 2013 - 11:54 AM

if(!empty($this->url)){
                                    $theURL = (isset($var[$this->modelName][$this->slugUrl]) && !empty($var[$this->modelName][$this->slugUrl]))
                                            ? $this->url."/".$var[$this->modelName][$this->slugUrl] : $this->url."/".$var[$this->modelName][$this->params];
                                    
                                    $str .= '<li ' . $selected . ' ' . $default_selected . '>';
                                    $str .= '<a  href="' . $theURL . '"><span>' . $name . $showCarret. '</span></a>';
                                    $str .= $sub;
                                    $str .= '</li>';
                                }else{
                                    $url = $this->getUrl($var);
                                    $str .= '<li ' . $selected . ' ' . $default_selected . '>';
                                    $str .= '<a  href="' . $url['url'] . '" ' . $url['target'] . '><span>' . $name . $showCarret. '</span></a>';
                                    $str .= $sub;
                                    $str .= '</li>';
                                }


Iain Rose (BSc)
Software Design & Development Engineer
365 On-Demand Solutions


#4 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 27 February 2013 - 11:54 AM

Okay which of those sections is the one being triggered?
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#5 244863

244863

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationGloucester
  • Age:26

Posted 27 February 2013 - 11:57 AM

the ELSE{}

 

$url = $this->getUrl($var);
                                    $str .= '<li ' . $selected . ' ' . $default_selected . '>';
                                    $str .= '<a  href="' . $url['url'] . '" ' . $url['target'] . '><span>' . $name . $showCarret. '</span></a>';
                                    $str .= $sub;
                                    $str .= '</li>';

 

It gives me this:

 

<a class="sf-with-ul" href="users/add">


Iain Rose (BSc)
Software Design & Development Engineer
365 On-Demand Solutions


#6 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 27 February 2013 - 11:57 AM

So try adding a / in front of the url.

I'd look into using the built in routing.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#7 244863

244863

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationGloucester
  • Age:26

Posted 27 February 2013 - 12:09 PM   Best Answer

added:

 

/index.php/

 

before the URL and it worked fine!!

 

thanks,


Iain Rose (BSc)
Software Design & Development Engineer
365 On-Demand Solutions





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com