2016-07-18 7 views
0

Ich paginieren zugeordnetes Modell in view() Funktion eines anderen Modells.CakePHP 3: findById wo größer als 0

public function view($id = null) 
    { 
     $category = $this->Categories->get($id, [ 
      'contain' => ['Subcategories'] 
     ]); 

     // paginate products 
     $products = $this->paginate($this->Categories->Products->findByCategoryId($category->id, ['conditions' => ['stock >' => 0, 'selling_price >' => 0]]), [ 
      'limit' => 21 
     ]); 

     $this->set('products', $products); 
     $this->set('category', $category); 
     $this->set('_serialize', ['category']); 
    } 

Ich möchte Daten einschränken zu finden, wo stock und selling_price größer als 0

Aber das funktioniert nicht. Wie man Bedingungen auf findById anwendet?

Antwort

1

Versuchen Sie folgendes:

$products = $this->paginate($this->Products->findByCategoryId($categoryId)->where(['stock >' => 0, 'selling_price >' => 0])->limit(21));

mit $ categoryId angegeben.