LoginSignup
3

More than 5 years have passed since last update.

PhalconのtoArrayはカラム指定できた

Last updated at Posted at 2015-06-17

知らなかったのでメモ

API作るときに、不要なカラムを除去する必要がありました。(Userのpasswordとか)
今までは、レコードのオブジェクトに対してtoArray()してからunset()していました。
しかし、よく調べてみたらカラム指定で抜き出すことができるようです。
もちろん、ResultSetにも使えるのでとっても便利。

$robot = Robots::findFirst(1);
$robotArray = $robot->toArray(array('id', 'name'));
$robots = Robots::find(array("type='virtual'", "order" => "name"));
$robotsArray = $robots->toArray(array('id', 'name'));

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
3