Reputation: 9978
I tried to pass url from current page to controller but it dosen't show me full url.
EX, http://xxxxxx.localhost/cards/card_list/page:2
when i echo it in controller it shows xxxxxx.localhost
. I knew because of the special character such as ("/" ":" )
...etc.
My project purpose is pass url with the form to controller after controller finished the work, I will redirect it to the current page.
card_list (View)
<?php echo $url5 = urlencode(Router::url($this->here, true)); ?>
<?php echo $form->create('CardSaleAll', array('url'=> array('controller' => 'cards', 'action' => 'complete_sale_card', $url5)));?>
<input type="hidden" name="data[CardSaleAll][sale_card_id]" value="'+id+'">
<?php echo $form->submit('Submit', array('alt' => '売却','type' => 'image', 'src' => '../../img/btn_52.png', 'style' => 'width: 307px;'));?>
cards (controller) => complete_sale_all (action)
function complete_sale_card($url5){
echo $url5;
exit();
}
Upvotes: 1
Views: 1598
Reputation: 66258
Normally a forward slash denotes a parameter delimiter:
I.e. the url /controller/action/one/two/three/four
maps to the following variables:
function action ($one, $two, $three, $four) {
}
If you want $one
to contain everything that follows the action name (in the above example) you can use a greedy-star route:
Router::connect(
'/anything/**',
array('controller' => 'cards', 'action' => 'complete_sale_card')
);
Instead of putting a url in the url, you can just make it a form field:
<?php
echo $form->create('CardSaleAll', array(
'action' => 'complete_sale_card'
));
echo $form->input('redirect', array(
'type'=> 'hidden',
'value' => $url5
));
?>
In the question there is this snippet:
<input type="hidden" name="data[CardSaleAll][sale_card_id]" value="'+id+'">
As well as being an error (unless id
really is a constant) it's a bad idea to write inputs by hand instead of letting cake generate them for you. If nothing else, because it's very easy to generate invalid markup or allow injection attacks. Instead replace with:
echo $this->Form->input('sale_card_id', array('type' => 'hidden'));
Or similar.
In the question there's also this:
'src' => '../../img/btn_52.png', 'style' => 'width: 307px;'
That's also a bad idea.
This will work for the url http://xxxxxx.localhost/cards/card_list/
(I assume) and fail for the url http://xxxxxx.localhost/cards/card_list
(no trailing slash).
Instead:
Router::url()
to generate the right absolute url.Upvotes: 0
Reputation: 922
Give the following a try
$this->request->url
The above should contain the URL as part of the current request for a view.
Upvotes: 1