CakePHP routes with sub-folders - cakephp

I have a problem with CakePHP route
Router::connect(
'/catalog/:slug/:slug2/*', array(
'controller'=>'pages',
'action'=>'view'
))
When I have url
/catalog/something/page:2 - it also catches this link. But it shouldn't, because there is no slash after params page:2, How to fix it? Thanks!!

I hope this may be helpful.
Router::connect(
'/catalog/:slug/:slug2/*', array(
'controller'=>'pages',
'action'=>'view'
), array('pass' => array('slug', 'slug2')));
and in your view file you can write like this to generate a link for above.
echo $this->Html->link('link', array(
'controller' => 'pages',
'action' => 'view',
'slug' => 'slug',
'slug2' => 'slug2'
));

Related

cakephp 2.5 Router - part of language string in URL

CakePHP Version 2.5.2
Config.Language 'spa'
If i'm in
mydomain.com/backoffice
and i reload (ctrl-r) i get again
mydomain.com/backoffice
If i call in UsersController in action deleteCache at the end:
return $this->redirect('/backoffice');
i get
mydomain.com/users/sbackoffice
Please note the "s" before backoffice. That seems to be a part of the config.language
If i set the Config.language to 'eng' i get
mydomain.com/users/ebackoffice
Please note now the 'e' before backoffice.
My routes.php:
Router::connect('/backoffice', array('controller' => 'users', 'action' => 'backoffice'));
Router::connect('/:language/:controller/:action/*',
array(),
array('language' => 'eng|spa')
);
Router::connect('/:language/:controller',
array('action' => 'index'),
array('language' => 'eng|spa')
);
Router::connect('/:language', array('controller' => 'technologies', 'action' => 'home'),
array('language' => 'eng|spa')
);
Any idea?
How can i debug this?

cakephp 2.6.1 ajax login not working

Having issues logging in with ajax. Can anyone direct me to some documentation that makes sense. This sounds worrying.
In 2.x $this->Auth->login($this->request->data) will log the user in
with whatever data is posted, whereas in 1.3
$this->Auth->login($this->data) would try to identify the user first
and only log in when successful.
$data['User']['email'] = "this";
$data['User']['password'] = "that";
$data = $this->request->input('json_decode', true);
$this->autoRender = false;
$this->response->type('json');
if ($this->Auth->login($data)){
echo "access";
} else {
echo "access denied";
}
It always prints "access".
In AppController.php
'Auth' => array(
'loginRedirect' => array(
'controller' => 'posts',
'action' => 'index'
),
'logoutRedirect' => array(
'controller' => 'pages',
'action' => 'display',
'home'
),
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email'),
'passwordHasher' => 'Blowfish'
),
)
),
Use AuthComponent::identify() instead. But this can (and clearly should) be done better. Your code tells me that you don't have much experience with json in CakePHP.
Check this page of the manual. Also your request should be made with "Accept: application/json" then your data should automatically end up in $this->request->data and then login() should pick it up automatically. The proper way is to send the Accept header and not just rely on the extension, this is general and not just specific to CakePHP.

Cakephp rerouting

Hi I d'like to be able to rewrite my url. I have this format of url:
localhost/example/urlrewriting/Links/view/1
and I want to change this url to
http://localhost/example/urlrewriting/tt/my-link-1
In my Routes.php I have done this:
Router::connect('tt/:slug-:id',
array('controller' =>'links', 'action' => 'test'),
array('pass' => array('slug', 'id'), 'slug' => '[a-z0-9\-]+', 'id' => '[0-9]+'));
and in my controller I have this
public function test($param1, $param2){
debug($this->request->params);
}
I've always find this answer:
TtController could not be found.
cakephp 2.4.1
Please add / before the connect params like:-
Router::connect('/tt/:slug-:id',
array('controller' =>'links', 'action' => 'test'),
array('pass' => array('slug', 'id'), 'slug' => '[a-z0-9\-]+', 'id' => '[0-9]+'));

How to maintain a variable in the url which is customized in cakephp?

What im trying to do here is maintain the variable 42 all throughout all pagination urls. I want my url to change from this
/exams/take/42/page:2
to this
/exams/take/42/items/2
Again,the number 42 is the variable..and the number 2 is the page number..Thanks.
UPDATE :
routes.php
Router::connect('/examinations/take/:id/page/:page',
array('controller' => 'examinations', 'action' => 'take'),
array(
'pass' => array('id', 'page'),
'id' => '[0-9]+',
'page' => '[0-9]+'
)
);
in the view/take
$this->Paginator->options(array('url' => $this->passedArgs));
AppController.php
public function beforeFilter(){
if (isset($this->request->params['page'])) {
$this->request->params['named']['page'] = $this->request->params['page'];
}
}
ive tried this ..but the generated url is the same,/examinations/take/42/page:2 ,when i click the next and prev links..
You've to define custom routes:
http://book.cakephp.org/2.0/en/development/routing.html
Example as below:
Router::connect(
'/exams/take/:id/items/:number',
array('controller' => 'exams', 'action' => 'take'),
array('pass' => array('id', 'number'))
);
Also you can get more information from below url try this:
http://www.sakic.net/blog/changing-cakephp-pagination-urls
yes you can do it with the use of custom routing. for more undrestanding you can see cakephp manual to manage custom routing in pagination
http://book.cakephp.org/2.0/en/development/routing.html
below will be your
e.g.
And by adding this route:
Router::connect('/:id/page/:page',
array('controller' => 'examinations', 'action' => 'take'),
array(
'pass' => array('id', 'page'),
'id' => '[0-9]+',
'page' => '[0-9]+'
)
);
and i does not work you can refer link

How to set cakephp edit form custom url?

HI,
im accessing my edit_view using the url
/controller/action/group_id/id
but when i check my action it is only using
/controller/action/id
i have already tried using the following.
$params = array('url' => array('controller' => 'controller','action'=> 'action',$group_id,$id))
$this->form(model,$params)
$params = array('url' => '/controller/action/group_id/id')
$this->form(model,$params)
but its still not working.
Thanks
Don't really know what $this->form() is, but try:
echo $this->Form->create('SomeModel', array(
'url' => array(
'controller' => 'controller',
'action' => 'action',
$param_1,
$param_2
)
));

Resources