2

私は現在、CakePHPに関するIBMのチュートリアルを進めています

ある時点で、次のコード スニペットに出くわしました。

<?php
class Dealer extends AppModel {
    var $name = 'Dealer';
    var $hasMany = array (
        'Product' => array(
            'className' => 'Product',
            'conditions'=>, // is this allowed?
            'order'=>, // same thing here
            'foreignKey'=>'dealer_id'
        )
    );
}
?>

実行すると、次のエラー メッセージが表示されます。

私は PHP の初心者なので、質問は次のとおりです。値が割り当てられていないキーを持つ配列を作成することは許可されていますか? 誰かがこのツタンカーメンで遊んで、何が起きているか知っていますか?

4

2 に答える 2

7

何も除外するのではなく、値 null を割り当てます。マニュアルによる

isset() は、NULL に設定された変数をテストすると FALSE を返します。

<?php
class Dealer extends AppModel
{
var $name = 'Dealer';
var $hasMany = array ('Product' => array(
'className' => 'Product',
'conditions'=> null,
'order'=> null,
'foreignKey'=>'dealer_id')
);
}
?>

これはうまくいきます。

于 2008-10-03T12:42:58.507 に答える
3

それは合法ですが、私が知る限り、null を割り当てて「空」であると明示的に言わなければなりません。

$hasMany = array ('Product' => array(
'className' => 'Product',
'conditions'=> null, // is this allowed?
'order'=> null, // same thing here
'foreignKey'=>'dealer_id'));

あなたが与えた例は非常に間違っているように聞こえます。おそらくうまくいかないはずです。

于 2008-10-03T12:42:47.617 に答える