Jump to content

[CakePHP] Problem calling info from a model


sanfly

Recommended Posts

In my Payment model I have the following

 

var $payMethodAll = array(

                '0' => 'Cash On Arrival',

                '1' => 'Direct Debit',

                '2' => 'Post (Cheque Only)',

                '3' => 'Credit Card',

                '4' => 'Account Credit',

                '5' => 'Account Credit + Direct Debit'

 

        );

 

In my Bookings controller, I call this data:

 

$pMethods = $this->Payment->payMethodAll;

 

And I get the following error:

 

Notice (8): Undefined property: AppModel::$payMethodAll [APP\controllers\bookings_controller.php, line 180]

 

This was working perfectly before but now all of a sudden is not.

 

I have tried clearing my tmp/cache/models

 

Im confused as to what the problem is, because in the bookings_controller I can use the model to get data from the database without issue: ie:

 

$p = $this->Payment->find('all');

 

works perfectly so not an issue with not having 'Payment' listed in $uses in my controller, or the model name being incorrect...

 

Any ideas?

Link to post
Share on other sites

If you are calling this from your bookings controller and it is associated with your payments, you need to properly link.

 

$this->Booking->Payment->payMethodAll

 

Wrong?  The OP's code looks right.  Seems he's either missing $uses or the var isn't declared as a class param...

 

class PaymentMethod extends AppModel {
    public $payMethodAll = array(
        '0' => 'Cash On Arrival',
        '1' => 'Direct Debit',
        '2' => 'Post (Cheque Only)',
        '3' => 'Credit Card',
        '4' => 'Account Credit',
        '5' => 'Account Credit + Direct Debit'
    );
    ...
}

class BookingController extends AppController {
    public $uses = ("PaymentMethod");

    public function myAction() {
         echo $this->PaymentMethod->payMethodAll;
    }
}

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.