【发布时间】:2017-09-19 10:06:26
【问题描述】:
我正在尝试保存观看次数以进行计数。它仅在经过身份验证的用户访问此页面时保存记录。当未经身份验证的用户访问此功能时保存失败。
use Cake\ORM\TableRegistry;
use Cake\Event\Event;
public function beforeFilter(Event $event)
{
$this->Auth->allow(['view']);
}
public function view($photoId = null)
{
$photoViewsTable = TableRegistry::get('PhotoViews');
$photoViews = $photoViewsTable->newEntity();
$photoViews->ip_address = $_SERVER['REMOTE_ADDR'];
$photoViews->photo_id = $photoId;
$photoViews->user_id = ($this->request->session()->read('Auth.User.id')) ? $this->request->session()->read('Auth.User.id') : 0;
$photoViews->ip_address = $_SERVER['REMOTE_ADDR'];
$photoViewsTable->save($photoViews);
}
【问题讨论】:
标签: cakephp cakephp-3.4 role-base-authorization