CakePHPの初心者です。
最近CakePHP3の勉強を始めたのですが、eclipseでCakePHP3のmodelのコードが補完されず、困っています。
eclipse上の関連がうまく行ってないのが原因だと感じたのですが、
どのように対応すれば良いのかがわからず、困っています。
一応下記サイトを参考に「AppController」クラスに@propertyを追加しましたが、メソッドを読み込んでくれません。
サイト:http://y-stream.blogspot.jp/2013/07/cakephp-eclipse-codehint.html
お手数おかけいたしますが、ご教示いただければ幸いです。
よろしくお願い致します。
###補足
1.開発環境
- eclipse4.5.1
- CakePHP3.1.5
2.モデル情報
Modelは自動生成したモデル
使用コマンド:bin\cake bake model persons
なお、生成されてソースは下記に添付いたします。
今回コードを補完したいのはPersonsTableクラスに入っている「newEntity」になります。
なお、コントローラークラスでは下記のように呼び出しております。
PHP
1class PersonsController extends AppController { 2 public function add() { 3 $person = $this->Persons->newEntity (); 4 } 5}
このCakePHPでインスタンス化されたPersonsTableクラスの「newEntity」というメソッドのコードを保管したいです。
お手数おかけいたしますが、何卒よろしくお願い致します。
・生成されたテーブルクラス
PHP
1<?php 2 3namespace App\Model\Table; 4 5use App\Model\Entity\Person; 6use Cake\ORM\Query; 7use Cake\ORM\RulesChecker; 8use Cake\ORM\Table; 9use Cake\Validation\Validator; 10 11/** 12 * Persons Model 13 */ 14class PersonsTable extends Table { 15 16 /** 17 * Initialize method 18 * 19 * @param array $config 20 * The configuration for the Table. 21 * @return void 22 */ 23 public function initialize(array $config) { 24 parent::initialize ($config); 25 26 $this->table ('persons'); 27 $this->displayField ('name'); 28 $this->primaryKey ('id'); 29 } 30 31 /** 32 * Default validation rules. 33 * 34 * @param \Cake\Validation\Validator $validator 35 * Validator instance. 36 * @return \Cake\Validation\Validator 37 */ 38 public function validationDefault(Validator $validator) { 39 $validator->add ('id', 'valid', [ 40 'rule' => 'numeric' ])->allowEmpty ('id', 'create'); 41 42 $validator->requirePresence ('name', 'create')->notEmpty ('name'); 43 44 $validator->add ('age', 'valid', [ 45 'rule' => 'numeric' ])->allowEmpty ('age'); 46 47 $validator->allowEmpty ('mail'); 48 49 return $validator; 50 } 51}
・生成されたEntitiyクラス
PHP
1<?php 2 3namespace App\Model\Entity; 4 5use Cake\ORM\Entity; 6 7/** 8 * Person Entity. 9 * 10 * @property int $id 11 * @property string $name 12 * @property int $age 13 * @property string $mail 14 */ 15class Person extends Entity { 16 17 /** 18 * Fields that can be mass assigned using newEntity() or patchEntity(). 19 * 20 * Note that when '*' is set to true, this allows all unspecified fields to 21 * be mass assigned. For security purposes, it is advised to set '*' to false 22 * (or remove it), and explicitly make individual fields accessible as needed. 23 * 24 * @var array 25 */ 26 protected $_accessible = [ 27 '*' => true, 28 'id' => false ]; 29} 30
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/12/15 07:38
2015/12/15 08:36
2015/12/16 00:58