我有一个控制器,通过uploadify处理上传的文件。问题是Auth::check('default')
始终返回 null 。所以我无法检查用户是否已登录并有权上传。
class UploadController extends \app\controllers\AppController {
// this works perfect, the auth configuration is printed out
public function index() {
$auth = Auth::check('default');
print_r($auth);
}
// this doesnt work
public function uploadify() {
$auth = Auth::check('default');
print_r($auth); // always empty!
...
}
}
通过uploadify调用uploadify
函数。我试图追溯问题,但我在StaticObject::_filter
结束,其中以下if语句返回true:
if (!isset(static::$_methodFilters[$class][$method])) {...}
这不同于index()
的调用,其中 if -statement未执行。但我不知道那里做了什么。
答案 0 :(得分:2)
感谢#li3我使用http://www.uploadify.com/forums/discussion/43/using-sessions-tricking-basic-authentication/p1
进行了这项工作在视图中我使用了scriptData:
'scriptData': { 'PHPSESSID': '<?php echo(session_id()); ?>'},
并在控制器中:
public function uploadify() {
$id = $_POST['PHPSESSID'];
session_id($id);
session_start();
$auth = Auth::check('default');
if ($auth == null) {
return $this->response->status = array('code' => 401, 'message' => 'Unauthorized');
}
...
}