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 comment
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 comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.