We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How can I get the entry ID via PHP for parsing on input?

Development and Programming

krislane's avatar
krislane
7 posts
15 years ago
krislane's avatar krislane

Hi folks,

I’m writing a template that parses PHP on input.

Basically I need to get the entry ID into PHP up front so I can then compose a query, get a row count, and use that to run a for loop inside which are my EE tags. Therefore, {entry_id} is not the answer.

Phew! I know it’s convoluted but that’s the way it’s got to be. Please help - the most likely candidate was this, but I wasn’t surprised it didn’t work:

$this->EE =& get_instance();
$this->EE->TMPL->fetch_param('entry_id');

I’ve spent hours on Google trying to get the magic keyword combo that returns the answer, so hopefully this is something that someone knows off the top of their head.

Cheers!

       
Greg Aker's avatar
Greg Aker
6,022 posts
15 years ago
Greg Aker's avatar Greg Aker

What are you trying to do? What’s your end goal? I think you’d be best served dropping the entry_id into a plugin.

       
krislane's avatar
krislane
7 posts
15 years ago
krislane's avatar krislane

Thanks for responding Greg.

The entry_id helps me contruct a query that will return a row count of data from P&T’s Matrix tables. With that, I can constrain a for loop that contains an NSM Transplant function (formerly LG Replace).

It’s taking images, quotes or related pages from Matrix fields and inserting them in the body text where NSM Transplant finds a tag, or ‘needle’.

It’s a development of AJ Penninga’s well-known technique at http://vimeo.com/5194268 except where he hard codes ‘needles’ 1, 2 and 3 etc, I added a PHP for loop that is really tidy, especially when this is doing one for each type of content, not just images.

Yeah I know, I could just set an arbitrary limit to the for loop, but I’m keen to make this as tidy as possible to alleviate any performance issues that may arise. I’m not much of a coder so this may just be paranoia, but we’re expecting the site to be popular so maybe it’s important.

Cheers!

       
krislane's avatar
krislane
7 posts
15 years ago
krislane's avatar krislane

BTW thanks for the plug-in suggestion - will look into it if there is not the simple answer to this I’ve been hoping for 😊

       
krislane's avatar
krislane
7 posts
15 years ago
krislane's avatar krislane

I spent a day exploring the plug-in route but I had parse order problems there (parse=”inward” didn’t help) and I don’t think it’ll ever work that way. I eliminated NSM Transplant as the cause by hard-coding a preg_replace into the plug-in. Matrix seems to parse early, and the only way to get an offset parameter to it is via PHP on input.

So, I’m still hoping someone knows how to get the entry_id via PHP, there must be an API call… Thanks!

FWIW here’s the code (the Matrix field is called Images):



Edit: can’t seem to correct those fancy quotes - they’re not slanted in the template, obviously.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.