Reputation: 347
Here is my action
public function actionUpload()
{
$model=new Sop;
if(isset($_FILES['files'])){
print_r($_POST['name']);exit;
$tmp_name = $_FILES['files']['tmp_name'][0];
$filename = $_FILES['files']['name'][0];
$new_url = Yii::app()->basePath."/docfile/".$filename;
move_uploaded_file($tmp_name, $new_url);
/*if(move_uploaded_file($tmp_name, $new_url)){
//print_r($filename);exit;
echo $filename;
}*/
}
else "error";
}
Now i want to pass $tmp_name , $ filename and $new_url to another action in this controller.
Upvotes: 2
Views: 2514
Reputation: 366
lets say you want to pass $tmp_name , $filename and $new_url parameters to an action named "next" in same controller, it can be done simply like this, in your actionUpload() call action next as $this->actionnext($tmp_name , $filename and $new_url).
public function actionUpload()
{
//code for actionupload()
$this->actionnext($tmp_name , $filename , $new_url); //call to next action.
}
in controller, definition of actionnext() should look like this:
public function actionnext($tmp_name , $filename , $new_url)
{
//your code goes here.
}
and in actionnext function defination "$tmp_name , $ filename , $new_url" are just variables so you can use any name here.
Upvotes: 0
Reputation: 472
You can use $this->forward('action')
to execute another action without redirecting to that url:
$params = array(
'tmp_name' => $tmp_name,
'filename' => $filename,
'new_url' => $new_url,
);
$action = $this->createUrl('controller/action', $params);
$this->forward($action);
The other action header could look like this:
public function actionAction($tmp_name, $filename, $new_url)
Upvotes: 0
Reputation: 93
I'm not exactly sure what you are trying to achieve as actions within controllers are designed to be processing requests and generating responses. It seems you are not using the Controller correctly.
If you however insist on using the controller-action you can use the redirect with a parameters as shown in the Documentation here: http://www.yiiframework.com/doc-2.0/yii-web-controller.html#redirect()-detail
An example could be (from inside a controller):
// /index.php?r=site/destination&tmp_name=$tmp_name&new_url=$new_url&filename=$filename
$this->redirect([
'site/destination',
'tmp_name' => $tmp_name,
'new_url' => $new_url,
'filename' => $filename,
]);
Please note that this is far from ideal. I'm not sure what you are trying to achieve but I would suggest using a Component for finishing the upload(?) job instead of sending parameters to a controller-action that finishes it.
Upvotes: 1