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

Passing the {segment_2} parameter to my Plugin

Development and Programming

Davmit's avatar
Davmit
11 posts
17 years ago
Davmit's avatar Davmit

Hi friends,

I am using a plugin for displaying data according to the {segment_2} But now i want to take the value of the {segment_2} inside my plugin to process my Query.

example : function test(“Here comes my {segment_2} value)

Can i do that?

Please guide me through this

Thanks, Davmit

[Moderator Edit: Moved to Plugin Technical Assistance forum]

       
silenz's avatar
silenz
1,648 posts
17 years ago
silenz's avatar silenz

It’s right there for you …

global $IN;
$segment_1 = $IN->SEGS[1];
$segment_2 = $IN->SEGS[2];
...
       
Daniel Walton's avatar
Daniel Walton
553 posts
17 years ago
Daniel Walton's avatar Daniel Walton

or, if you plan on using the plugin on other templates where you might be checking on segment 3/4/5 etc:

On template:

{exp:my_plugin my_parameter="{segment_2}"}
 etc...
{/exp:my_plugin}

And within the plugin:

global $TMPL;
$my_parameter = $TMPL->fetch_param('my_parameter');
       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones
It’s right there for you …
global $IN;
$segment_1 = $IN->SEGS[1];
$segment_2 = $IN->SEGS[2];
...

Might want to either check that $IN->SEGS[#} is set before calling it directly, or simply use $IN->fetch_uri_segment()

       
Daniel Walton's avatar
Daniel Walton
553 posts
17 years ago
Daniel Walton's avatar Daniel Walton

And don’t forget to $DB->escape_str(‘value’) your segment 2 variable first :D, Derek will not be happy…

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones
And don’t forget to $DB->escape_str(‘value’) your segment 2 variable first :D, Derek will not be happy…

My torch for escaped input is always lit and ready to burn! :-D

       

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.