dancingAngel
dancingAngel

Reputation: 67

Cakephp function in model

I develop a website using cakephp. But the response time is too slow. So, I want to implement fat model and skinny controller.

But i got

Call to a member function fashionpage() on a non-object

when calling fashionpage function in controller.

I have Home model(relationship: Home hasMany Cart)

My controller:

public function fashionlist() {
        $user = $this->Auth->user('id');

        $counter = $this->Home->fashionpage($user);
        $this->set(compact('user', 'counter'));
    }

My model:

public function fashionpage($user = null) {
        return $this->Home->Cart->find('count', array('conditions'=>
                                                   array('conditions'=>array('User.id'=>$user))));
      }

can anyone please help me.

Upvotes: 0

Views: 88

Answers (2)

pramod
pramod

Reputation: 2318

You must call it with persistent object I think

Upvotes: 0

arilia
arilia

Reputation: 9398

There's an error in your model. In fact when you are in your Model file $this is the Model (Home in your case), so no need to do $this->Home->Cart, but just $this->Cart

so not

public function fashionpage($user = null) {
        return $this->Home->Cart->find('count', array('conditions'=>
                                                   array('conditions'=>array('User.id'=>$user))));
      }

but

public function fashionpage($user = null) {
        return $this->Cart->find('count', array('conditions'=>
                                                   array('conditions'=>array('User.id'=>$user))));
      }

Upvotes: 1

Related Questions