// Controller
// Build query
$options = array();
$options['sortBy'] = $product_sort;
$options['sortDirection'] = 'ASC';
$options['PriceLevel'] = $PriceLevel;
if (!empty($searchField)) $options[$searchField] = $search;
if (!empty($category)) $options['category'] = $category;
if (!empty($onsale)) $options['onsale'] = 'Y';
$data['products'] = $this->product_model->getRecords($options);
// Model
function getRecords($options = array())
{
// Qualifications
$this->db->select('cat_imagePath');
$this->db->join('categories', 'categories.Category_id = inventory.Category_id');
$this->db->where('categories.active', 'Yes');
$this->db->where('inventory.Istatus', 'A');
if (isset($options['Item']))
$this->db->where('Item', $options['Item']);
if (isset($options['searchField']))
$this->db->like($options['searchField'], $options['searchData']);
$query = $this->db->get('inventory');
return $query->result();
}
$result = Model_Inventory::find()
->related('categories')
->where('categories.active', '=', 'Yes')
->where('Istatus', '=', 'A')
->get();
and add extra clauses to your query if needed. $result = Model_Inventory::find();
$result->related('categories');
$result->where('categories.active', '=', 'Yes');
$result->where('Istatus', '=', 'A');
$result->get();
But not very clean... It looks like you're new here. If you want to get involved, click one of these buttons!