# Passing entire channel entry to plugin

I'm relatively new to ExpressionEngine, and apologise if this seems obtuse!

I have channel entries with a lot of fields associated with them (each channel entry will typically have 20+ channel fields), and I wanted to know if there was a way to pass all those fields to my plugin somehow by just sending through the entire entry itself as a parameter?

Currently, I'm trying to avoid something like this:

{exp:channel:entries channel="my_news" limit="10"}
{exp:my_plugin:process_something field1="" field2="" field3="" ... field40=""}
{/exp:channel:entries}


Is there an easy and efficient way to send through all those field values to my plugin? Or alternatively, get the entry itself in the plugin and just pass the entry ID as the parameter, something like:

{exp:channel:entries channel="my_news" limit="10"}
{exp:my_plugin:process_something entry_id="{entry_id}"}
{/exp:channel:entries}


...and then in the plugin:

public function process_something()
{
$entry_id = ee()->TMPL->fetch_param('entry_id');$entry = < some function / method to get the entry and its details > ;
}


Is there something to make this possible? I hope this makes sense, and thank you for any help!

By default plugin tags inside modules is executed before parent module. To change the order you need to add parse="inward" parameter to exp:channel:entries tag

{exp:channel:entries channel="my_news" limit="10" parse="inward"}
{exp:my_plugin:process_something entry_id="{entry_id}"}
{/exp:channel:entries}

• Hey Max, thanks for this! I'm fairly new to EE - could you possibly expand on your thoughts and show me how this would fit into my plugin function? Thank you in advance! Dec 2 '13 at 20:20
• well, you code looks fine, the only issue was that at the moment when you code was executed, ee()->TMPL->fetch_param('entry_id') has "{entry_id}" as string, not entry_id (as 112, 123, 1244 etc.) Dec 2 '13 at 22:50
• Actually, that works just fine as a way to pass the entry ID to my plugin function...have I missed something? Also, I've posted my current solution as an answer to my OP if you're interested in checking it out! :) Dec 3 '13 at 9:19

For anyone interested, I eventually went with the following. It provides the essential functionality I was looking for. If anyone has any pointers, suggestions or alternative solutions, please don't hesitate to provide them as I'm still fairly new to EE and will consider them as applicable answers!

First off, in my template:

{exp:channel:entries channel="my_news" limit="10"}
{exp:my_plugin:process entry_id="{entry_id}"}
{/exp:channel:entries}


Next, my plugin, located in \system\expressionengine\third_party\my_plugin\pi.my_plugin.php:

<?php

class My_plugin {

public $return_data; public function __construct() {$this->return_data = '';
}

public function process() {

// get the entry data...
$entry_id = ee()->TMPL->fetch_param('entry_id');$sql = 'select * from ' . ee()->db->dbprefix('channel_data') .
' where entry_id = "'. $entry_id .'"';$select = ee()->db->query($sql); if ($select->num_rows() > 0) {
$row =$select->row();
// do something with the data...
}
}
}

• I would be cautious with this approach, as you're essentially requerying for the same data that the channel:entries tag has already queried for. Not a big deal if you're not doing this a lot, but you might consider a different approach to reduce queries and improve performance, depending on what you're trying to do within the plugin. Dec 4 '13 at 1:05
• Hey @JeremyGimbel, thanks for your insight! I'm actually looking to submit a bunch of entity data to a web service, which the plugin will be processing, but I'm trying to just get that entity data to the plugin somehow. Could you perhaps provide an example? I'm still quite new to EE, obviously ;) Dec 4 '13 at 8:06
• Is the channel entries tag you have in your example code exactly as you have it in your template? Or did you simplify it? Dec 4 '13 at 13:19
• @JeremyGimbel - everything you see, both in my original post as well as my answer, are exactly the same as I'm currently using it, save for the process_something() function at the top with its pseudo code ;) Jan 8 '14 at 8:41