0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHP2でstatic function内からモデルのプロパティへアクセスする

Last updated at Posted at 2018-07-24

概要

CakePHP2のComponentに実装した静的メソッド内から、モデルのプロパティへアクセスする必要があったのでメモ。
静的メソッド内からは$this->Model->propertyではアクセスできない1 ので、別の方法で対応。

対応方法

public static function foo() {
  $val = ClassRegistry::init('Model')->property;
  ...
}
  1. PHPオブジェクト指向入門(前半) 内の 「静的プロパティ / 静的メソッド / クラス定数

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?