I'm querying an external timetable database, and I need to get the start and end points of the journey to use in a hidden field.
My template code looks like this:
{exp:get_piers:departure_pier cruise_id="{cruise_id}"}
and
{exp:get_piers:arrival_pier cruise_id="{cruise_id}"}
{cruise_id} is simply a numeric value that is set in the EE channel, but relates to the external database.
So I've created a plugin that looks like this:
class Get_piers {
public $return_data;
public $cruise_id;
/**
* Constructor
*/
public function __construct()
{
$this->EE =& get_instance();
//get cruise id from template tag
$this->cruise_id = $this->EE->TMPL->fetch_param('cruise_id');
//connect to external db
$this->bookings_db = $this->EE->load->database('timetable', TRUE);
}
// ----------------------------------------------------------------
/**
* Departure Point
*/
function departure_pier() {
$piers = $this->bookings_db->select('depPier')
->from('tbl_cruises')
->where('cruiseID', $this->cruise_id)
->get();
return $piers->row('depPier');
}
function arrival_pier() {
$piers = $this->bookings_db->select('arrPier')
->from('tbl_cruises')
->where('cruiseID', $this->cruise_id)
->get();
return $piers->row('arrPier');
}
The problem is that the value for $this->cruise_id is showing in the query as '0', but if I try to return just the value for $this->cruise_id (outside the sql), I get the correct number passed through from the template.
What am I missing? I'm guessing its something to do with visibility inside/outside the function, but having tried lots of alternatives, it just ain't working for me.
Can anyone offer any pointers?
$this->cruise_id
inside ofdeparture_pier()
instead of inside the constructor?Cannot re-assign $this
$sql = "SELECT depPier FROM tbl_cruises WHERE cruiseID = $this->cruise_id"
to screen, I get the query I want, but when I try and execute it, it seem its then that the$this->cruise_id
variable is being nulled or zero'd.depPier
FROMtbl_cruises
WHERE cruiseID=".$this->cruise_id;