I am newbie in Yii2. Please help me to achieve this. I want to know how to create absoluteurl in yii2. I have tried the code given below but I want something different.
echo Yii::$app->urlManager->createAbsoluteUrl(['site/confirm', 'id' => $user->id,'code' => $user->token,'&']);
output is http://car-rental.demoinja.com/site/confirm/69?code=275a9253dfc81efa47be4fdf1fc6a927&1=%26
But I want the url like this
http://car-rental.demoinja.com/site/confirm/?id=69&code=275a9253dfc81efa47be4fdf1fc6a927
No need to add '&' in createAbsoluteUrl function; so you need to use following function.
<?php echo Yii::$app->urlManager->createAbsoluteUrl(['site/confirm', 'id' => $user->id,'code' => $user->token]); ?>
Related
I work with Laminas and in a ControllerAction function I want to redirect to another url as a post by using $this->redirect()->toRoute('newSite', $noURLParams, $options);
When I use the "query"-Option ($options = [$query => ['postPara1' => 'blabla', 'postPara2' => 'blubblub']]), I will get the "post"-Parameter as GET-Parameter in the URL:
hhttp://localhost/new-site?postPara1=blabla&postPara2=blubblub
So everyone could see the content of the parameters.
Is there a way to get the toRoute() to make a "POST" out of it?
Or do I have to use another function for this?
Thank you for your interest and help. After you said that it doesn't work, I changed the sequence of what, when should be called and now I can do it without an additional redirect.
I found the documentation just fine, but for the life of me I can't figure out how to set up the FieldMasks in PHP to update a CloudSchedulerClient.
The command should be like this:
$client->updateJob($job, $updateMask); but no matter what I set the $updateMask variable to, my code keeps saying Expect Google\Protobuf\FieldMask. If for instance I wanted to update the description of a cron job to "test", 'description' => 'test', how should I go about that?
If you share some code, that would be helpful.
The error suggests that you are not providing the proper type. Your code should look something like this:
use Google\Protobuf\FieldMask;
$updateMask = new FieldMask([
'paths' => ['description']
]);
$client->updateJob($job, $updateMask);
As of my knowledge these both are used for creating links :
What is the main difference between $this->Html->url and $this->Html->link in Cakephp?
Is there any performance issues occurs for using these?
What if i want to open link in new tab using "$this->Html->url"
What i tried :
<?php echo $this->Html->url($item['News']['link'],array('target'=>'_blank', 'escape' => false)); ?>
but its not working. open link in same tab.
Thanks in advance.
Well, according to CakePHP Documentation, the HTML->url takes two arguments, the 2nd one is a boolean while the first is a routing array. Try this:
<?php echo
$this->Html->url(
array(
'href' => $item['News']['link'],
'target' => '_blank',
'escape' => false
),
false // Second argument, true means prepend the path of my site before the link while false means don't prepend
); ?>
References:
http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::url
http://book.cakephp.org/2.0/en/appendices/glossary.html#term-routing-array
This is what the $this->Html->link() method is for. It takes an array of options as parameters to do this.
Hi I've got some form for uploading files through php script, where user pick a one category, than second sub-category and then type of file.
I have to upload it on server into correct directory and path will looks like ..../category/sub-category/type/file.xxx --- and then I put whole absolute path to my database
By now I've got triple nested switch, is there any other way how to do it in better way?
Thanks a lot!
There is a pic of HTML code and PHP -- > http://oi59.tinypic.com/352qclx.jpg
Not sure at what point does the switch come in. However, can't you just do something like following in a single statement?
$complete_filepath = "..../$category/$sub_category/$type/$filename";
May be a multi-demension array will help you to solve it. like this:
$arr_dir_conf = array("dir_conf" =>
array("category1" =>
array("sub_category1" =>
array("type1" => "directory/category1/sub_category1/type1"),
...
array("typen" => "directory/category1/sub_category1/typen")
),
...
array("sub_categoryn" =>
...
),
),
...
);
Then you just use the array like this:
move_uploaded_files($_FILES['file']['tmp_name'],
$arr_dir_conf[$category][$subcategory][$type]);
This is a CakePHP / General PHP question.
In my application I use a query string like /login?continue=/admin/posts
This query string is used to redirect users to the URL in the query, but it doesn't work so it seems as though the app can't see the string...
This has got me wondering as basically when you arrive at the page with the string it's a GET request where as when you login, it becomes a POST or XML request (if using AJAX). Do I need to add the query string manually to the form for the POST to see it?
Either in the form action or a hidden input? Or am I barking up the wrong tree?
I'm currently grabbing the query like so:
if(isset($this->params['url']['continue']))
{
$pathtoredirect = $this->params['url']['continue'];
}
else
{
$pathtoredirect = $this->Auth->redirect();
}
But that's within the POST request so perhaps the query is lost... and adding it to a hidden input would not solve the problem with the current code so I would either change the code to look at the hidden field or pass the query with the action on the form?
e.g. <form action="/login?continue=/admin/posts" method="post">
Am I correct in thinking this? And would anyone be able to offer solutions or pros and cons of the two methods I mention?
In short I'm asking how to add the query string to my form action value
It currently looks like:
php echo $this->Form->create('User',
array(
'id' => 'loginform',
'type' => 'post',
'url' => array
(
'admin'=>false,
'controller' => 'users',
'action' => 'login'
)
)
);
So how would I add the query string to the form?
Thanks
When receiving a POST request you can receive both POST and GET variables through the superglobals $_POST and $_GET.
You can either send your paramater in $_GET by including it in the form's action attribute or send it in $_POST by creating an <input type="hidden"> tag within the form
A slash (/) is a reserved character. Encode it with %2F.
http://blooberry.com/indexdot/html/topics/urlencoding.htm#whatwhy
The solution was to do this:
<?php echo $this->Form->create('User',
array('id' => 'loginform', 'type' => 'post',
'url' => array('admin'=>false,'controller'=>'users','action'=>'login','url'=>$this->params['url']['continue']))); ?>
as I have a route already setup to handle the additional URL parameter:
Router::connect('/auth/login', array('controller'=>'users','action'=>'login'));
Router::connect('/auth/login?continue=:url',
array('controller'=>'users','action'=>'login'),
array(
'url' => '[A-Za-z0-9/\._-]+',
'pass' => array('url')
));
If anyone sees any issues with the way I do this though, please feel free to comment.