CakePHP 2.2.3
I have something like this:
$this->Html->link('here',
array(
'controller' => 'biz',
'action' => 'search',
'range' => '1+3'),
array('escape' => false));
When I click on this link the url will be encoded like this:
/biz/search/range:1%2B3
But I need
/biz/search/range:1+3
Is there any way to switch off url encoding or should I change my controller which parses the named parameter??
Try using:
$this->Html->link('here',
array(
'controller' => 'biz',
'action' => 'search',
'range' => '1\+3'),
array('escape' => '\'));
Simply can you try this
//search.ctp
echo $this->Html->link('here', '/biz/search/range:1+3');
Receive this in controller
//BizController.php
public function search() {
var_dump($this->request->params['named']);
// do something
}
Related
I created custom url route like this:
Router::connect('/subjects.details', array(
'plugin' => 'subjects',
'controller' => 'subjects',
'action' => 'details'
));
However that action/view needs a parameter.
So when I go to link like localhost/foo/subjects.details/12 it gives me missing controller error.
Missing Controller
Error: Subjects.detailsController could not be found.
Error: Create the class Subjects.detailsController below in file:
app/Controller/Subjects.detailsController.php
How do I add id param for this url?
You have to define the param in the url and in your action as well:
Router::connect('/subjects.details/:id', array(
'plugin' => 'subjects',
'controller' => 'subjects',
'action' => 'details'
));
Lasers answer returned another error. It basically added new key 'id' => '1' into $this->params array instead into $this->params 's 'passed' key array. By changing it into this it works:
Router::connect('/subjects.details/*', array(
'plugin' => 'subjects',
'controller' => 'subjects',
'action' => 'details'
));
Here is a working solution. You have to passed the params and then it'll start working. Here is the way-
Router::connect('/subjects.details/:id', [
'plugin' => 'subjects',
'controller' => 'subjects',
'action' => 'details'
],
[
'pass' => ['id']
]
);
And your method should look like this-
public function details($id){
//....
}
I hope this can be helpful. Thanks.
Using this code:
$sitemap = 4;
$link = $this->Html->link( $sitemap . '.xml', null,
array('plugin' => $this->request->plugin,
'controller' => $this->request->controller,
'action' => 'view',
'admin' => false));
I expect to get a link that looks like this:
http://www.domain.com/vreb_listings/vreb_listing_feeds/view/4.xml
Instead, I get this:
/admin/vreb_listings/vreb_listing_feeds/4.xml
What gives? The action => view is having no effect, as view doesn't show up in the url, and the admin => false isn't working either, as admin does show up. This code is in the admin area.
I haven't even looked up how to include the full domain path in the url. Also, I want the title text to be the same as the url.
According to docs, the second parameter is the url one, so in your code it should be
$link = $this->Html->link( $sitemap . '.xml',
array('plugin' => $this->request->plugin,
'controller' => $this->request->controller,
'action' => 'view',
'admin' => false));
(remove the null second parameter)
Oh, and for title text, that is the third parameter, so
$link = $this->Html->link( $sitemap . '.xml',
array('plugin' => $this->request->plugin,
'controller' => $this->request->controller,
'action' => 'view',
'admin' => false),
array('title' => $sitemap.'.xml'));
should do the trick
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]+'));
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
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
)
));