Welcome Guest, Not a member yet? Register   Sign In
Calculate value with data from another model
#1

Hi, this is code from my seminar model:

PHP Code:
// Seminar Model

public function find_by_id($id) {
 
$this->load->model('Seminar_date_model''seminar_date');
 
$query $this->db->where('seminar_id'$id)->get('seminar_dates');
 
$seminar_dates$query->custom_result_object('Seminar_date_model');
 
 
$query $this->db->where('id'$id)->get('seminars');
 
$result $query->custom_row_object(0'Seminar_model');
 
$result->seminar_dates $seminar_dates;
 return 
$result;
}

public function 
get_seminar_dates() {
    // if i call $this->seminar_dates->price() there are no seminar data
    return $this->seminar_dates;


In the seminar_dates model i want to calculate a price and need data from the seminar model. How can i solve this?
Getting the seminar_date model with an seminar is easy, because then i have access to the seminar property in the seminar_date model by doing this:

PHP Code:
// Seminar_date Model

public function find_by_id($id) {
    $query $this->db->where('id'$id)->get('seminar_dates');
    $result $query->custom_row_object(0'Seminar_date_model');
 
    $this->load->model('Seminar_model''seminar');
    $query $this->db->where('id'$result->seminar_id)->get('seminars');
    $seminar $query->custom_row_object('Seminar_model');
    $result->seminar $seminar;

    return $result;
}

public function 
price() {
    // seminar data available 
    return $this->seminar->price $this->coupon;

Reply


Messages In This Thread
Calculate value with data from another model - by groovebird - 03-29-2020, 05:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB