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}"}


{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')
            ->where('cruiseID', $this->cruise_id)
    return $piers->row('depPier');

function arrival_pier() {   
    $piers = $this->bookings_db->select('arrPier')
            ->where('cruiseID', $this->cruise_id)
    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?

  • 2
    Have you tried setting $this->cruise_id inside of departure_pier() instead of inside the constructor? – Derek Hogue Jun 5 '14 at 17:36
  • Derek Hogue, please submit this as an answer. – Johnathan Waters Jun 5 '14 at 20:16
  • Hi Derek, yes, I tried this and got the following fatal error. Cannot re-assign $this – Andrew Armitage Jun 5 '14 at 20:44
  • Tried a couple more alternatives, but no progress yet. If I output $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. – Andrew Armitage Jun 5 '14 at 21:42
  • What do you get if you manually construct your query rather than use EE/CI helpers to build it? ie $query="SELECT depPier FROM tbl_cruises WHERE cruiseID=".$this->cruise_id; – foamcow Jun 6 '14 at 9:57

Numpty alert...fixed. The original code was in fact working fine, I had a stray tag in my template that had an empty parameter value - hence the null value in the SQL.


  • Should we close the question? – Sobral Jun 5 '14 at 22:54
  • Yes - by all means - sorry :-) – Andrew Armitage Jun 5 '14 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.