如何使用cakephp从表中只获取一行

时间:2016-07-29 02:11:17

标签: cakephp cakephp-3.0

我尝试使用cakephp从表的某一行检索数据,我想从提取的行中获取值。

P.S。我试图跟随cakephp的find(),但没有得到任何东西,反而得到了错误。         Error`$ login_id = $ this-> AppAuth-> user(' id');         $ userSettings = $ this-> loadModel(" UserSettings");

    $userSetting= $this->$userSettings->find('first', array(
    'conditions' => array('UserSettings.user_id' => $login_id)));`

2 个答案:

答案 0 :(得分:0)

From cakephp site明白了。

$query = $internSettings->find('all', [ 'conditions' => ['InternSettings.intern_id' => $login_id] ]); $row = $query->first();

现在我可以检索一行,我怎么想访问行的值?

答案 1 :(得分:0)

$record = $internSettings->find('all', [ 'conditions' => ['InternSettings.intern_id' => $login_id]])->first();

这将返回$record中的实体对象,您可以通过

访问字段
echo $record->field_name;

或者您可以将其转换为数组,然后您可以访问

$recordArr=$record->toArray();
echo $recordArr['field_name'];