Reputation: 1997
I'm pretty new to Yii, so this might be a silly question. I must be missing something somewhere. Plz help me out. I have just written a simple code while I'm learning Yii. I have a spark controller which has an action that looks like this:
public function actionDownload($name){
$filecontent=file_get_contents('images/spark/'.$name);
header("Content-Type: text/plain");
header("Content-disposition: attachment; filename=$name");
header("Pragma: no-cache");
echo $filecontent;
exit;
}
Now I have enabled SEO friendly URLs and echo statement in the view file to display the returned download file name. But when I go to the URL, SITE_NAME/index.php/spark/download/db5250efc9a9684ceaa25cacedef81cd.pdf I get error 400 - your request is invalid.
Plz let me know if I am missing something here.
Upvotes: 0
Views: 8905
Reputation: 555
Make sure if you are properly supplying the parameter name
($name
) in your request.
Use
SITE_NAME/index.php/spark/download/name/db5250efc9a9684ceaa25cacedef81cd.pdf
or
SITE_NAME/index.php/spark/download?name=db5250efc9a9684ceaa25cacedef81cd.pdf
instead of just SITE_NAME/index.php/spark/download/db5250efc9a9684ceaa25cacedef81cd.pdf
Upvotes: 0
Reputation: 1697
Yii keeps an eye on the params you pass into an action
function. Any params you pass must match what's in $_GET
.
So if you're passing $name
then you need to make sure there's $_GET['name']
available.
So check your URL manager in /config/main.php
, and make sure you're declaring a GET var:
'spark/download/<name:[a-z0-9]+>' => 'site/download', // Setting up $_GET['name']
Otherwise change your function to the correct param variable:
public function actionDownload($anotherName){
}
Upvotes: 4
Reputation: 466
Did you create the URL correct? You should do it best with
Yii::app()->createUrl('/spark/download',array('name'=>$filename));
Upvotes: 1