1

find() と findBySql() はどちらも、すべての属性が連結された文字列を返しますが、これはあまり役に立ちません。

        $customers = Customer::model()->find("
            CONCAT( fName, ' ', lName ) LIKE  ?
            ", array( '%' . $searchVal . '%'));

オブジェクトや配列などの便利なものを取得するにはどうすればよいのでしょうか?

        $str = '';
        foreach ($customers as $customer){
            $str .= "<option>" . $customer->fName . " " . $customer->lName . "</option>" ;
        }
4

3 に答える 3

4

誰もロボトミーされませんでした。実際、データベースのクエリに使用できる関数がいくつかあり、それらはすべてさまざまなシナリオで役立ちます。

find() returns the first row satisfying the specified condition
findByPk() returns the row with the specified primary key
findByAttributes() returns the first row using the specified SQL statement
findBySql() returns the first row using the specified SQL statement
findAll() returns all rows satisfying the specified condition
findAllByPk() returns all rows with the specified primary keys
findAllByAttributes() returns all rows with the specified attribute values
findAllBySql() returns all rows using the specified SQL statement

これらの関数にはすべて用途があります。シナリオに適したものを使用してください。

于 2013-10-05T19:54:04.000 に答える