i'm having troubles with my routes.php file, in the past my applcation works fine with the routes like this:
Router::connect( '/imprenta_online/:family/:subfamily/:id/:title/:quantity_id/:description/:days/*',
array('controller' => 'imprenta_online', 'action' => 'home'),
array('pass' => array('slug','slug', 'id','slug', 'slug', 'quantity_id', 'slug', 'slug')
));
but now, the SEO manager needs to remove the controller from the url, i'm trying to do it in the routes.php and, first, this change works for THIS URLS, but all the routes that uses the prefix backend (backend_index, backend_edit...) show me errors on paginate...
I'm not "good" whit this, so i'd like to know what can i do???
I need some help to know which changes i need to do, all the others routes works by default with cake routes, so i didn't have to changes them.
Related
We are converting an exisiting HTML site into a CMS using CakePHP. Since SEO of the site has been mapped with keywords and indexed by Google the static pages i want to have urls to have the extention .html
I had a look at the Document here
But am not quite sure how to achieve this in the right way.
Any one who has worked on it can give some pointers?
simply put this line into your Router Router::parseExtensions('html');
This will tell the Router to cut off the .html as an Extension and parse what remains.
To Create correct Links to the Pages you have to give the Link() function another Parameter called "ext".
Like this:
$this->Html->link(
'Super Seo link',
array(
'controller' => 'anyController',
'action' => 'someAction',
'title' => 'seo-title-for-gods-sake',
'ext' => 'html'
) );
Have fun! Florian
I'm using CakePHP to one of my project. When I was designing the URL, I know CakePHP does well when I use
$this->Html->Link('Add Post', array('controller'=>'posts', 'action'=>'edit', 1234))
CakePHP will generate URI /appname/posts/edit/1234. But what I'm thinking /appname/post/1234/edit is better than the former one. I couldn't find a solution to workaround with it.
I've tried
$this->Html->Link('Add Post', array('controller'=>'posts', 1234, 'action'=>'edit'))
but CakePHP will ignore the order of array.
Does anyone know how to achieve this URL? Basically I don't want to modify function Router::url, what I need is to write code in my ctp view file and CakePHP to know the right order I put. How can I do that?
BTW, I'm using CakePHP 2.3.
This is a job for routing, more specifically reverse routing : http://book.cakephp.org/2.0/en/development/routing.html
In app/Config/routes.php you could add something along the lines of the following:
Router::connect(
'/:controller/:id/:action',
array('controller' => 'posts', 'action' => 'edit'),
array('id' => '[0-9]+')
);
Here, you tell Cake to reverse route any request coming from the edit method of the posts controller by defining the order of pre-route named parameters. In your view, the link should be constructed like this:
echo $this->Html->link('Add Post', array(
'controller' => 'posts',
'action' => 'edit',
'id' => 1234
));
Note the extra id parameter being passed that we assigned in routes.php. The Url should look like:
http://appdomain.com/posts/1234/edit
In my humble opinion, this is considered bad practice both from a conventional and SEO standpoint.
I was explaining to our SEO specialist that cakephp url structure is domain/controller/view/params
so to view a particular product the URL might be something like this:
example.com/products/show/product-name-slug
This would then map to the show function on the products controller with the product-name-slug as a parameter so it could render the correct product page.
He thought this was good but asked if I could name the controller p and the view d so the url would then be:
example.com/p/d/product-name-slug
Since this would make the appropriate keywords (product-name-slug) have a higher ratio over the entire url.
I understand where he is coming from, from a SEO perspective but this make no sense from a programming perspective giving controllers and views single letter names.
Does the ambiguous controller/view names in the URL make that much of a difference? If so, what would be a good compromising solution?
having additional route in configuration:
example.com/seo/product-name-slug would make code and SEO person happy
Router::connect(
'/seo/:slug',
array('controller' => 'products', 'action' => 'show'),
array(
'pass' => array('slug')
)
);
It makes a big difference what is in your URL. I never ever used the default URL structure of CakePHP. It is good to have it by default, but it would make an unacceptable constraint.
Cake wouldn't be worthy to be called a framework if it couldn't map actions to arbitrary URLs http://book.cakephp.org/2.0/en/development/routing.html#route-elements
You can even match regexp to actions:
Router::connect(
'/:controller/:year/:month/:day',
array('action' => 'index', 'day' => null),
array(
'year' => '[12][0-9]{3}',
'month' => '0[1-9]|1[012]',
'day' => '0[1-9]|[12][0-9]|3[01]'
)
);
I've a new question :)
I'll briefly explain what I'm trying to achieve. Right now I have an url that looks like this.
/products/index/brand:figleaves
I want this to look like this
/brand/figleaves
By writing the following route rule I get what I want.
Router::connect('/brand/:brand/*', array('controller' => 'products', 'action' => 'index'));
Everything goes fine, but then I discovered the pagination logic has been destructed.
If I click on 'next page' I get redirected to the url /products/index/page:2.
it doesn't pass the brand parameter
it redirects back to the products_controller and not to the url I defined in the route rule.
In fact I'd need this as url /brand/figleaves/page:2.
Strange thing is if I browse to /products/index/brand:figleaves and click on Next, then I get redirected to /brand/figleaves/page:2. How can this be explained?
I'd appreciate some help with this :)
Kind Regards,
Laurent
For those interested in how I solved this.
I just defined some options in the paginator in my view and passed the value explicitly, like this.
$this->Paginator->options(array
('url'=> array(
'controller' => 'products',
'action' => 'index',
'brand'=>$this->params['brand']
)));
That does the job :)
I have just successfully installed CakePHP and I see that I can edit the home.ctp view but is there a default controller for the index page?
To change the content of this page, create: APP/views/pages/home.ctp.
To change its layout, create: APP/views/layouts/default.ctp.
You can also add some CSS styles for your pages at: APP/webroot/css.
If you want to make modifications to this controller it is recommended that you copy the default
cake/libs/controller/pages_controller.php to app/controller/pages_controller.php
The reason is because you should not modify anything inside the "cake" folder where any file can be overwriten when updating your application with the latest cakephp version.
You can change the default behavior by changing the Route::connect() function arguments such as below:
Router::connect('/', array('controller' => 'requests', 'action' => 'index', 'home'));
and also if you want to connect all the actions to one action, use the code below in the same config file:
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
Of course you should change the arguments to your own needs.
This configuration is located under app/config/routes.php.
To get more information about Route::connect(), visit this page: http://api.cakephp.org/class/router#method-Routerconnect
Yes, the default controller is PagesController, located in:
cake/libs/controller/pages_controller.php