I’ve done a lot with .NET developemnt but am now supporting our company EE2 site. I want to have an EE2 page set up that can receive a variable as a part of the URL or a user session variable (or any other way you might suggest).
In .NET I would have the root URL appended with “?myvariable=foo” and then in the web page I would parce the “foo” and assign it to a textbox. Can someone help this lost soul?
Instead of querystrings I would use EE style URIs and use segments.
That is, instead of http://site.com/?myvar=foo
Make the uri http://site.com/foo and test for {segment_1 == 'foo'} in the template.
There are lots of ways to slice this donkey, including using querystrings (as you are used to) but you’ll probably have to mess with the .htaccess rules the remove index.php from the URIs (so you have clean URLs) to allow for it.
Learn more about the way EE urls work: http://ellislab.com/expressionengine/user-guide/general/urls.html
Thanks so much and please forgive this novice at EE and PHP. So you are saying I could create a URI to go to the “donate” page of alarm-inc.org and pass a paramter “foo” as follows:
http://www.alarm-inc.org/donate/foo
And the “donate” page would use the paramater to fill a textbox as follows:
<input type=”text” name=”designation” value=”<?php echo $this=>EE->input->{segment_1}(‘designation’); ?>” >
and the “designation” textfield would initially display “foo”?
Actually it’s easier than that. Note, in your example, donate is segment 1, foo is sement 2 (unless you didn’t install EE in root of your site).
<input type=“text” name=“designation” value=”{segment_2}” />
http://www.alarm-inc.org/donate/foo would then output
<input type=“text” name=“designation” value=”foo” />
http://www.alarm-inc.org/donate/amilliondollars would then output
<input type=“text” name=“designation” value=”amilliondollars” />
A little wild - http://alarm-inc.org/get_involved/donate/foo
<input type=“text” name=“pg_billto_postal_name_first” value=”{segment_3}” /> yields “foo” (with the quotes)
This is almost what I want except for the quotes
Can anyone help me strip the quotes from the beginning and end?
Ah so it sounds like you’re not using EE templates? Just the framework then? You have your work cut out for you!
Here’s some code I used recently for custom paging (using DB assets outside my EE install so couldn’t/didn’t want to use channels). Maybe helpful reference for you.
Re: stripping quotes, I remember reading about something against using preg_replace() in EE for performance reasons, not sure, you may have to google around for that.
My setup uses URIs like http://site.com/search_result/50/page5/ (50 is the page result set size, and page5 would be the 5th page of results.
//look at third URI segment for page size, default to 25 if not found
$page_size = $this->EE->uri->segment(3, 25);
//look at fourth URI segment for page number, default to 'page1' if not found
//use substring to remove 'page' from URI
$page_current = substr($this->EE->uri->segment(4, 'page1'),4);
$page_start = ($page_size * ($page_current - 1)) + 1; //first row of the current page set
$page_end = ($page_start + $page_size) - 1; //last row of the current pageNow using:
http://alarm-inc.org/get_involved/donate
<input type=“text” name=“pg_billto_postal_name_first” value={segment_3} />
yields a “/” (without the quotes)
I changed it to <input type=“text” name=“pg_billto_postal_name_first” value={segment_3}>
And it works in with and without the third segment “foo” http://alarm-inc.org/get_involved/donate and http://alarm-inc.org/get_involved/donate/foo
both work.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.