0

我正在尝试创建一个从 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('*'),
        ),
    );
}

用户身份.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;
}

我会尽我所能尝试这种方法,但如果无法解决,是否还有另一种最好的方法来制作“下载链接”?

4

1 回答 1

0

该操作view2未在您的 中列为允许的操作accessRules,因此它将触及deny底部的规则。

于 2013-07-23T05:40:26.283 回答