我目前正在努力学习IBM关于CakePHP 的教程
有一次,我遇到了以下代码片段:
<?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'
)
);
}
?>
当我运行它时,我收到以下错误消息:"解析错误:语法错误,第7行/Applications/MAMP/htdocs/cakehp/app/models/product.php中的意外','"
我是PHP的n00b,所以我的问题是:是否允许在没有赋值的情况下使用键创建数组?有人玩过这个芭蕾舞团吗?知道发生了什么事吗?
将值赋值为null,而不是遗漏任何内容。手册上写着
如果测试已设置为NULL 的变量,isset()将返回FALSE
<?php
class Dealer extends AppModel
{
var $name = 'Dealer';
var $hasMany = array(
'Product' => array(
'className' => 'Product',
'conditions' => null,
'order' => null,
'foreignKey' => 'dealer_id'
)
);
}
?>
这很好用。
它是合法的,尽管据我所知,你必须通过给它赋值null来明确地说它是"空的",
$hasMany = array ('Product' => array(
'className' => 'Product',
'conditions'=> null, // is this allowed?
'order'=> null, // same thing here
'foreignKey'=>'dealer_id'));
你举的这个例子听起来非常错误,可能不应该奏效,因为事实并非如此。