LoginSignup
0
1

More than 5 years have passed since last update.

Cake2でURL直打ちでのアクセスを拒否する

Last updated at Posted at 2015-09-11

Cake2でURL直打ちでのアクセスを拒否する

画面上で非表示にしているが、データがあるためURL直打ちだとアクセスできてしまうことがあるので、それを防ぐ方法。

Controller


public function detail($id = null) {
       $conditions = array('Model.delete_flag' => 0);

       if (!$this->Model->exists($id, $conditions)) {
          $this->redirect(array('controller' => 'home', 'action' => 'index'));
       }
}

Model

    public function exists($id = null, $additionalConditions = null) {
        if ($id === null) {
            $id = $this->getID();
        }
        if ($id === false) {
            return false;
        }
        $conditions = array($this->alias . '.' . $this->primaryKey => $id);
        if ($this->schema('delete_flag') != null) {
            $conditions[$this->alias . '.delete_flag'] = 0;
        }
        if ($additionalConditions !== null && is_array($additionalConditions)) {
            $conditions = array_merge($conditions, $additionalConditions);
        }
        return (bool) $this->find('count', array('conditions' => $conditions, 'recursive' => -1, 'callbacks' => false));
    }
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1