cakephp 2.x使用treelist中的限制

时间:2015-05-29 22:03:04

标签: php cakephp

我必须使用Treelist,因为左边和右边的字段。我还没有找到限制结果的方法,因为我只需要顶部元素:

$lis = $this->Record->find('list', array(
    'conditions' => array('Record.pnumber' => $id),
    'fields' => array('Record.state_id'),
));

$options = array('NOT' => array('State.id' => $lis));

//How can i use limit here? I only need to get the first element (i have to use the tree structure because the lft field store the arrengment in this case) So 'limit'=>1 but how and where?

$statelists = $this->Record->State->generateTreeList(
    $options, null, null, null, null
);

请不要使用正常find('first', $options)方式,因为我需要树形结构。我在Api中读到我可以像查找一样使用条件,但限制不是条件的一部分。

1 个答案:

答案 0 :(得分:0)

我强迫了treelist.Insted使用普通列表:

$statelists=$this->Record->State->find('list',array(
            'conditions'=>$options,
            'fields'=>array('State.name'),
            'order'=>array('State.lft'),
            'recursive'=>0,
            'limit'=>1
                    )
            );