2

I am currently plowing my way through IBM's tutorial on CakePHP

At one point I run into this snippet of code:

<?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'
        )
    );
}
?>

When I run it I get the following error-message: "Parse error: syntax error, unexpected ',' in /Applications/MAMP/htdocs/cakephp/app/models/product.php on line 7"

I'm a n00b at PHP so my question is: is it allowed to make an array with keys without assigned values? Has anybody played around with this tut and know what is up?

2 Answers 2

8

Assign the value null instead of leaving anything out. The manual says

isset() will return FALSE if testing a variable that has been set to NULL

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

This works fine.

Sign up to request clarification or add additional context in comments.

Comments

3

It is legal, though as far as I'm aware, you have to explicitly say it's 'empty' by assigning null to it,

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

The example you've given sounds very wrong, and probably shouldn't work, as it isn't.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.