my findByAttributes error

Need Help!

Why when i use "findByAttributes" always got error Invalid argument supplied for foreach()




 public function getMenu($cnd = " IS NULL")  {

        $data2 = array();


      foreach (HumanresourceMenu::model()->findByAttributes('parent' . $cnd, 'stat=1') as $models) {

            $row = array();

            $row['label'] = $models->label;

            $row['url'] = array($models->url);

            if (count($this->getMenu2(' =' . $models->id)) > 0) {

                $row['items'] = $this->getMenu2(' =' . $models->id);

            }

            $data2[] = $row;

        }


        return $data2;

    }


    public function getMenu2($cnd = " IS NULL") {

        $data2 = array();

        foreach (HumanresourceMenu::model()->findByAttributes('parent' . $cnd, 'stat=1') as $models) {

            $row = array();

            $row['label'] = $models->label;

            $row['url'] = array($models->url);

            if (count($this->getMenu2(' =' . $models->id)) > 0)

                $row['items'] = $this->getMenu2(' =' . $models->id);

            $data2[] = $row;

        }


        return $data2;

    }



Try the following lines:




HumanresourceMenu::model()->findByAttributes(array('stat'=>1), 'parent'.$cnd);


OR


HumanresourceMenu::model()->find('stat = :stat AND parent '.$cnd, array(':stat'=>1));

you should just carefully read documentation:

findByAttributes() Finds a single active record that has the specified attribute values.

findAllByAttributes() Finds all active records that have the specified attribute values.