いつもお世話になっております。
idを指定してDBから1レコードの情報($user)を取得しているのですが、
id,email,created,modifiedの4つの情報しか取得できずに困っています。
カラム情報を全て取得したい場合はどのようにすればよろしいのでしょうか。
(Modelはcakephpのbakeで作成しました)
ご教示のほどお願いいたします。
- $this->log($user);で見た結果
Error: { "id": 1, "email": "test@test.test", "created": "2016-06-27T13:30:57+0900", "modified": "2016-07-19T18:15:52+0900" }
- src/Controller/IndexController.php
<?php namespace App\Controller; use App\Controller\ApiAppController; use Cake\ORM\TableRegistry; class IndexController extends ApiAppController { public function index() { $this->loadComponent("Auth"); $this->Auth->config([ "authenticate" => [ "Form" => [ "fields" => [ "username" => "email", "password" => "password" ] ] ] ]); if ($this->Auth->identify()) { $id = $this->Auth->identify()["id"]; $trUsers = TableRegistry::get("Users"); $user = $trUsers->get($id); //こちらの値を上記に記載しています。
- src/Model/Table/UsersTable.php
<?php namespace App\Model\Table; use App\Model\Entity\User; use Cake\ORM\Query; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; class UsersTable extends Table { public function initialize(array $config) { parent::initialize($config); $this->table('users'); $this->displayField('id'); $this->primaryKey('id'); $this->addBehavior('Timestamp'); $this->belongsTo('Companys', [ 'foreignKey' => 'companys_id', 'joinType' => 'INNER' ]); $this->belongsTo('Groups', [ 'foreignKey' => 'groups_id', 'joinType' => 'INNER' ]); $this->hasMany('Contents', [ 'foreignKey' => 'user_id' ]); $this->hasMany('Operationlogs', [ 'foreignKey' => 'user_id' ]); } public function validationDefault(Validator $validator) { $validator ->allowEmpty('id', 'create'); $validator ->requirePresence('name', 'create') ->notEmpty('name'); $validator ->email('email') ->requirePresence('email', 'create') ->notEmpty('email'); $validator ->requirePresence('password', 'create') ->notEmpty('password'); $validator ->integer('size') ->requirePresence('size', 'create') ->notEmpty('size'); $validator ->requirePresence('active', 'create') ->notEmpty('active'); $validator ->requirePresence('role', 'create') ->notEmpty('role'); return $validator; } public function buildRules(RulesChecker $rules) { $rules->add($rules->isUnique(['email'])); $rules->add($rules->existsIn(['companys_id'], 'Companys')); $rules->add($rules->existsIn(['groups_id'], 'Groups')); return $rules; } }
- src/Model/Entity/User.php
<?php namespace App\Model\Entity; use Cake\ORM\Entity; class User extends Entity { protected $_accessible = [ '*' => false, 'id' => false, ]; protected $_hidden = [ 'password' ]; }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/20 04:59
2016/07/20 05:36 編集
2016/07/20 05:57