题
我目前正在通过 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/cakephp/app/models/product.php”中/ p>
我是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'));
你给出的例子听起来非常错误,可能不应该工作,因为它不是。
不隶属于 StackOverflow