Questions tagged [cakephp-routing]

Routing is a feature that maps URLs to controller actions.

It was added to CakePHP to make pretty URLs more configurable and flexible. Using Apache’s mod_rewrite is not required for using routes, but it will make your address bar look much more tidy.

Routes in an application are configured in app/Config/routes.php.

Manual Reference.

Example:

Router::connect(
    '/pages/*',
    array('controller' => 'pages', 'action' => 'display')
);

This route is found in the routes.php file distributed with CakePHP. This route matches any URL starting with /pages/ and hands it to the display() action of the PagesController(); The request /pages/products would be mapped to PagesController->display('products').

46 questions
9
votes
1 answer

Pass Query string to cake style URL in cakephp and give ext of HTML

What I am trying to achieve: When user passes this: /results?val=real&x=1&y=0 it should show: /results/real.html?x=1&y=0 and from Action I should still be able to access $this->request->query['val'] which should be equal to real What I have done…
Keval Domadia
  • 4,768
  • 1
  • 37
  • 64
6
votes
2 answers

CORS preflight channel did not succeed. Only in Firefox. Chrome works fine

So I have an unusual issue that Im not sure how to go about debugging. I have an angular 4 application that uses cakephp on the server side. In my application I have a number of different screens that I can access ok except for one and its only an…
briansexton
  • 175
  • 1
  • 1
  • 11
3
votes
3 answers

Cake PHP Routing issue in 2.0Beta

I'm upgrading a dev site to Cake 2.0 Beta and my custom routing appears to be broken. The previous site routed the url /login to the Employees controller, action:login. This is the code setting up the routes: Router::connect('/login',…
Ben Brocka
  • 2,006
  • 4
  • 34
  • 53
3
votes
1 answer

CakePHP 3.x: all routes to the plugin

This is not a real question, I need a confirmation to know if I understand what I'm studying (the routes of CakePHP). I have the plugin MyPlugin. By default, all requests should be directed to the plugin, so I wish that the plugin name doesn't…
Mirko Pagliai
  • 1,220
  • 1
  • 19
  • 36
3
votes
1 answer

Automatically convert from dashes to underscores using the Cake PHP router

I've been setting up some routes like this: Router::connect('/background/a-page', array('controller' => 'background', 'action' => 'a_page')); Router::connect('/background/another-page', array('controller' => 'background', 'action' =>…
tekniskt
  • 483
  • 3
  • 10
2
votes
1 answer

How do I validate URL, but ignore if http:// or blank?

I want to validate a form field for URL. I have set the default for the field to http://. When the user doesn't enter a URL, and leaves the http://, it says invalid URL. URL is not required, so if it's only http://, it should not show error message.…
codemonkey613
  • 960
  • 1
  • 16
  • 26
2
votes
1 answer

CakePHP 3 Routing: How to route controller basis

I am using cakephp 3. I want to hide frontends controller in url. My Routes config: Router::connect('/:action', array('controller' => 'frontends')); And I want to refer all function to bloggers controller when url start as…
Abdus Sattar Bhuiyan
  • 3,016
  • 4
  • 38
  • 72
2
votes
1 answer

Link with another prefix on a Previously prefixed page in cakephp:2.5.4

I am trying to achieve the link as cake_proj/prefix2/controller2/action on this page who's link is - cake-proj/ but 'prefix1' => true in my routes.php as this is the home page, so ultimately its link is cake_proj/prefix1/controller1/action. So now I…
Iglance3
  • 105
  • 1
  • 11
2
votes
3 answers

Prevent CakePHP controller access with routing

I'm following the CakePHP blog tutorial, and at the moment the URL /posts/view/1 Works. Using routing, I managed to create an alias news: Router::connect('/news/:action/*', array('controller' => 'posts')); Router::connect('/news/*',…
yesman
  • 7,165
  • 15
  • 52
  • 117
1
vote
1 answer

How can I force all URI requests to index.php?

In my index.php (which is in my project root directory) I have a basic routing system that grabs the url (using $_SERVER[‘REQUEST_URI]) and calls the proper ‘controller’ which then calls the proper ‘view’ (so, implementation of very basic MVC). What…
Abdul SH
  • 67
  • 7
1
vote
2 answers

cakephp 3 prefix routing

I'm trying to set up a routing prefix in cakephp 3 so any URLs starting with /json/ get the prefix key set and I can change the layout accordingly in the app controller. Other than that, they should use the usual controller and action. I have added…
TimSpEdge
  • 49
  • 2
  • 9
1
vote
1 answer

Cakephp routing controller alias

I'm trying to do the same as this site, stackoverflow, do with their URLs. CakePHP works like this: website/controller/action/ I want to config routing to achieve this: myWebSite.com/questions/(question_id)/(question)/ eg:…
user1148875
  • 449
  • 4
  • 11
  • 24
1
vote
1 answer

How to redefine the URLs generation without changes at the HtmlHelper#link(...) calls in CakePHP?

I have a CakePHP website with many internal links, that are build with the HtmlHelper: /app/View/MyController/myaction.ctp Html->link( $item['Search']['name'], array( 'controller' => 'targetcontroller', …
automatix
  • 14,018
  • 26
  • 105
  • 230
1
vote
1 answer

CakePHP routing same action, different route for different params

I want to connect the following routes: register/about_you my_profile/edit/about_you ...to the same action. But I want the second route to bring in a parameter that I can use to identify that we are on the edit page, not registration. I currently…
Will
  • 1,893
  • 4
  • 29
  • 42
1
vote
3 answers

How to get a list of items from a category to show on a single page cakephp

I am having problems trying to get my cake application to display items from the database on a single page based on the url of the page... For example I want to display items that are in the "Party" category and I type "mydomain.com/All/party" in…
1
2 3 4