我正在尝试从yii文件夹创建一个下载文件的链接,链接可以显示但是当我点击它时显示错误Error 403 You are not authorized to perform this action.
这些是我的代码:
public function actionView2($id)
{
$this->render('view2',array(
'model'=>$this->loadModel($id),
));
}
_view.php
<b><?php echo CHtml::encode($data->getAttributeLabel('image')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->image), array('view2', 'id'=>$data->image), array('target'=>'_blank'));
?>
<br />
view2.php
<h1>View2 #<?php echo $model->image; ?></h1>
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'image',
),
)); ?>
我认为它是由授权引起的,或类似的东西,但我在accessRules或UserIdentity.php中没有改变任何内容
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
UserIdentity.php
public function authenticate()
{
$users=array(
// username => password
'demo'=>'demo',
'admin'=>'admin',
);
if(!isset($users[$this->username]))
$this->errorCode=self::ERROR_USERNAME_INVALID;
elseif($users[$this->username]!==$this->password)
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
$this->errorCode=self::ERROR_NONE;
return !$this->errorCode;
}
我会尽可能努力地尝试这种方法,但如果无法解决这个问题,还有另一种最佳方式来进行“下载链接”吗?
答案 0 :(得分:0)
行动view2
未在accessRules
中列为允许的操作,因此它会点击底部的deny
规则。