<?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>Better Help World</title>
	<atom:link href="http://www.betterhelpworld.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.betterhelpworld.com</link>
	<description>Web development, PHP and Codeigniter</description>
	<lastBuildDate>Tue, 02 Aug 2011 15:39:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to create custom 404 page with Codeigniter</title>
		<link>http://www.betterhelpworld.com/codeigniter/how-to-create-custom-404-page-with-codeigniter</link>
		<comments>http://www.betterhelpworld.com/codeigniter/how-to-create-custom-404-page-with-codeigniter#comments</comments>
		<pubDate>Thu, 23 Jun 2011 21:34:28 +0000</pubDate>
		<dc:creator>msnisha</dc:creator>
				<category><![CDATA[Codeigniter]]></category>
		<category><![CDATA[404 Page]]></category>
		<category><![CDATA[Custom]]></category>
		<category><![CDATA[Error]]></category>

		<guid isPermaLink="false">http://www.betterhelpworld.com/?p=53</guid>
		<description><![CDATA[It is always nice to have a good Page-not-found page to keep a good impression on your website even when the link is broken. Here is how I have implemented it on www.LankaMatters.com in 3 steps. First open routes.php in application/config and set a custom controller name. Create a new controller and write the following...]]></description>
			<content:encoded><![CDATA[<p>It is always nice to have a good Page-not-found page to keep a good impression on your website even when the link is broken. Here is how I have implemented it on <a title="Lanka Matters" href="http://www.LankaMatters.com">www.LankaMatters.com</a> in 3 steps.</p>
<ol>
<li>First open routes.php in application/config and set a custom controller name.</li>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">In config/routes.php</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="re0">$route</span><span class="br0">&#91;</span><span class="st_h">'404_override'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'my404'</span><span class="sy0">;</span> <span class="co1">//Here my404 is my controller class name.</span></pre></div></div>
<li>Create a new controller and write the following code in it. The code is very easy to understand. So I am not going to explain it here.</li>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">my404.php</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span><br />
<span class="kw2">class</span> my404 <span class="kw2">extends</span> CI_Controller<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp;         parent<span class="sy0">::</span>__construct<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> index<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">$this</span><span class="sy0">-&gt;</span><span class="me1">output</span><span class="sy0">-&gt;</span><span class="me1">set_status_header</span><span class="br0">&#40;</span><span class="st_h">'404'</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$data</span><span class="br0">&#91;</span><span class="st_h">'content'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'error_404'</span><span class="sy0">;</span> <span class="co1">// View name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">load</span><span class="sy0">-&gt;</span><span class="me1">view</span><span class="br0">&#40;</span><span class="st_h">'index'</span><span class="sy0">,</span><span class="re0">$data</span><span class="br0">&#41;</span><span class="sy0">;</span><span class="co1">//loading in my template</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="sy1">?&gt;</span></div></div></div>
<li>Create a view with your custom message.</li>
</ol>
<p>That is all. <img src='http://www.betterhelpworld.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.betterhelpworld.com/codeigniter/how-to-create-custom-404-page-with-codeigniter/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to post on user&#8217;s wall on Facebook?</title>
		<link>http://www.betterhelpworld.com/codeigniter/how-to-post-to-users-wall-on-facebook</link>
		<comments>http://www.betterhelpworld.com/codeigniter/how-to-post-to-users-wall-on-facebook#comments</comments>
		<pubDate>Mon, 20 Jun 2011 20:41:36 +0000</pubDate>
		<dc:creator>msnisha</dc:creator>
				<category><![CDATA[Codeigniter]]></category>
		<category><![CDATA[Download]]></category>
		<category><![CDATA[Facebook connect]]></category>
		<category><![CDATA[Feed]]></category>
		<category><![CDATA[Graph API]]></category>
		<category><![CDATA[Librayr]]></category>
		<category><![CDATA[Wall Post]]></category>

		<guid isPermaLink="false">http://www.betterhelpworld.com/?p=42</guid>
		<description><![CDATA[You can download the source code here Facebook connect for Codeigniter to experiment immediately. Hope you have aldreay went through my tutorial on Codeigniter library for Facebook. If not please go through it first. Once user is authenticated with the required access tokens, you can call any methods mentioned in the Graph API at http://developers.facebook.com/docs/reference/api/. Now I will...]]></description>
			<content:encoded><![CDATA[<p>You can download the source code here <strong><a href="http://www.betterhelpworld.com/wp-content/uploads/2011/06/Facebook-connect-for-Codeigniter.zip">Facebook connect for Codeigniter</a></strong> to experiment immediately.</p>
<p><a href="http://www.betterhelpworld.com/wp-content/uploads/2011/06/Facebook-connect-for-Codeigniter.zip"></a>Hope you have aldreay went through my tutorial on Codeigniter library for Facebook. If not please go through it first.</p>
<p>Once user is authenticated with the required access tokens, you can call any methods mentioned in the Graph API at <a href="http://developers.facebook.com/docs/reference/api/">http://developers.facebook.com/docs/reference/api/</a>. Now I will explain how to call the Graph api method to post to the user wall.</p>
<p>Simply write the following function inside the Facebook connect library you have already created. After that you can simply call the function with the wanted details. If user is not loggedcin or no access to post then the function will return false.</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">function</span> post_to_wall<span class="br0">&#40;</span><span class="re0">$message</span><span class="sy0">,</span><span class="re0">$link</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span><span class="sy0">,</span><span class="re0">$photourl</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">fbSession</span><span class="br0">&#41;</span>
	<span class="br0">&#123;</span>
		<span class="re0">$param</span> <span class="sy0">=</span> <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st_h">'message'</span><span class="sy0">=&gt;</span><span class="re0">$message</span><span class="sy0">,</span><span class="st_h">'cb'</span> <span class="sy0">=&gt;</span> <span class="st_h">''</span><span class="br0">&#41;</span><span class="sy0">;</span>           
		<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$photourl</span><span class="sy0">!=</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
		<span class="br0">&#123;</span>
			<span class="re0">$param</span><span class="br0">&#91;</span><span class="st0">&quot;picture&quot;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re0">$photourl</span><span class="sy0">;</span>
		<span class="br0">&#125;</span>
		<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$link</span><span class="sy0">!=</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
			<span class="re0">$param</span><span class="br0">&#91;</span><span class="st0">&quot;link&quot;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="re0">$link</span><span class="sy0">;</span>               
		<span class="re0">$posts</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">fb</span><span class="sy0">-&gt;</span><span class="me1">api</span><span class="br0">&#40;</span><span class="st_h">'/me/feed'</span><span class="sy0">,</span><span class="st_h">'post'</span><span class="sy0">,</span><span class="re0">$param</span><span class="br0">&#41;</span><span class="sy0">;</span>
		<span class="kw1">return</span> <span class="kw4">TRUE</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
	<span class="kw1">else</span>
	<span class="br0">&#123;</span>
		<span class="kw1">return</span> <span class="kw4">FALSE</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>&nbsp;</p>
<p>Same way if you want to get user&#8217;s wall posts pass &#8220;me/home&#8221; to the fb-&gt;api method in the above functions.</p>
<p>Hope you learned something. For complete reference of the available functions refer the <a href="http://developers.facebook.com/docs/reference/api/">Facebook Graph API.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.betterhelpworld.com/codeigniter/how-to-post-to-users-wall-on-facebook/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Removing index.php from website url &#8211; Codeigniter</title>
		<link>http://www.betterhelpworld.com/codeigniter/removed-index_php_url</link>
		<comments>http://www.betterhelpworld.com/codeigniter/removed-index_php_url#comments</comments>
		<pubDate>Mon, 13 Jun 2011 11:00:03 +0000</pubDate>
		<dc:creator>msnisha</dc:creator>
				<category><![CDATA[Codeigniter]]></category>
		<category><![CDATA[SEO Friendly URL]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">http://www.betterhelpworld.com/?p=32</guid>
		<description><![CDATA[If you are using Codeigniter sometimes you may feel bore with the index.php in the url. By removing it from the url you can make your website more structured and it will help you in SEO matrices. Enable the apache ModRewrite module. If you are using wamp server you do it by using the menu...]]></description>
			<content:encoded><![CDATA[<p>If you are using Codeigniter sometimes you may feel bore with the index.php in the url. By removing it from the url you can make your website more structured and it will help you in SEO matrices.</p>
<ol>
<li>Enable the apache ModRewrite module. If you are using wamp server you do it by using the menu in the task bar icon.</li>
<li>Open <strong>config.php</strong> from <strong>system/application/config</strong> directory and replace <strong>$config['index_page'] = “index.php” b</strong>y <strong>$config['index_page'] =&#8221;</strong></li>
<li>Now create the .htaccess file in your web root and add the following lines in it.</li>
</ol>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]</pre></div></div>
<p>4. Please if you have installed your Codeigniter in some folder in root the you have to set the base folder to that. For doing it copy paste the following after the first line in step 3. Replace test with the actual folder name.</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="text" style="font-family:monospace;">RewriteBase /test/</pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.betterhelpworld.com/codeigniter/removed-index_php_url/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A smart Codeigniter model for all functions</title>
		<link>http://www.betterhelpworld.com/codeigniter/a-smart-codeigniter-model</link>
		<comments>http://www.betterhelpworld.com/codeigniter/a-smart-codeigniter-model#comments</comments>
		<pubDate>Sat, 11 Jun 2011 22:06:37 +0000</pubDate>
		<dc:creator>msnisha</dc:creator>
				<category><![CDATA[Codeigniter]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Model]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.betterhelpworld.com/?p=26</guid>
		<description><![CDATA[Today tip is about extending the Codeigniter Model core class by adding some smart functions to it. After extending it, you no longer required to write any code in your model, except extending your model from our extended Model class and everything will be handled by extended class. Before continuing with this, I assume you...]]></description>
			<content:encoded><![CDATA[<p>Today tip is about extending the Codeigniter Model core class by adding some smart functions to it. After extending it, you no longer required to write any code in your model, except extending your model from our extended Model class and everything will be handled by extended class.<br />
Before continuing with this, I assume you have some experience working with Codeigniter framework and know the folder strucure in it. As the first step, create a file in application/core folder and name it as &#8220;MY_model.php&#8221;.<br />
Define our new model class in it extending Codeigniter core Model class. The coding will be like the following in first stage.</p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span> <span class="kw1">if</span> <span class="br0">&#40;</span> <span class="sy0">!</span> <a href="http://www.php.net/defined"><span class="kw3">defined</span></a><span class="br0">&#40;</span><span class="st_h">'BASEPATH'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <a href="http://www.php.net/exit"><span class="kw3">exit</span></a><span class="br0">&#40;</span><span class="st_h">'No direct script access allowed'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw2">class</span> MY_Model <span class="kw2">extends</span> CI_Model
<span class="br0">&#123;</span>
	<span class="kw2">public</span> <span class="re0">$table</span><span class="sy0">;</span>
	<span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="br0">&#41;</span>
	<span class="br0">&#123;</span>
		parent<span class="sy0">::</span>__construct<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
		<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">table</span> <span class="sy0">=</span> <a href="http://www.php.net/get_class"><span class="kw3">get_Class</span></a><span class="br0">&#40;</span><span class="re0">$this</span><span class="br0">&#41;</span><span class="sy0">;</span>
		<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">load</span><span class="sy0">-&gt;</span><span class="me1">database</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>In the above part we have added a constructor and a variable named $table. We are initializing the $table variable with the class name. We will use the class name as the table name in our methods, when table name is not passed to the mthods.</p>
<p>We are going to have 4 methods insert, update, search and save. Method names self explains the functionality. Method save will update the record when a record already exists with same parimary and inserts if no such record exists.</p>
<p>&nbsp;</p>
<div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">public</span> <span class="kw2">function</span> save<span class="br0">&#40;</span><span class="re0">$data</span><span class="sy0">,</span><span class="re0">$tablename</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$tablename</span><span class="sy0">==</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
	<span class="br0">&#123;</span>
		<span class="re0">$tablename</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">table</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
	<span class="re0">$op</span> <span class="sy0">=</span> <span class="st_h">'update'</span><span class="sy0">;</span>
	<span class="re0">$keyExists</span> <span class="sy0">=</span> <span class="kw4">FALSE</span><span class="sy0">;</span>
	<span class="re0">$fields</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">field_data</span><span class="br0">&#40;</span><span class="re0">$tablename</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$fields</span> <span class="kw1">as</span> <span class="re0">$field</span><span class="br0">&#41;</span>
	<span class="br0">&#123;</span>
		<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$field</span><span class="sy0">-&gt;</span><span class="me1">primary_key</span><span class="sy0">==</span>1<span class="br0">&#41;</span>
		<span class="br0">&#123;</span>
			<span class="re0">$keyExists</span> <span class="sy0">=</span> <span class="kw4">TRUE</span><span class="sy0">;</span>
			<span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$data</span><span class="br0">&#91;</span><span class="re0">$field</span><span class="sy0">-&gt;</span><span class="me1">name</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>
			<span class="br0">&#123;</span>
				<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">where</span><span class="br0">&#40;</span><span class="re0">$field</span><span class="sy0">-&gt;</span><span class="me1">name</span><span class="sy0">,</span> <span class="re0">$data</span><span class="br0">&#91;</span><span class="re0">$field</span><span class="sy0">-&gt;</span><span class="me1">name</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
			<span class="br0">&#125;</span>
			<span class="kw1">else</span>
			<span class="br0">&#123;</span>
				<span class="re0">$op</span> <span class="sy0">=</span> <span class="st_h">'insert'</span><span class="sy0">;</span>
			<span class="br0">&#125;</span>
		<span class="br0">&#125;</span>
	<span class="br0">&#125;</span>
&nbsp;
	<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$keyExists</span> <span class="sy0">&amp;&amp;</span> <span class="re0">$op</span><span class="sy0">==</span><span class="st_h">'update'</span><span class="br0">&#41;</span>
	<span class="br0">&#123;</span>
		<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">set</span><span class="br0">&#40;</span><span class="re0">$data</span><span class="br0">&#41;</span><span class="sy0">;</span>
		<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">update</span><span class="br0">&#40;</span><span class="re0">$tablename</span><span class="br0">&#41;</span><span class="sy0">;</span>
		<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">affected_rows</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">==</span>1<span class="br0">&#41;</span>
		<span class="br0">&#123;</span>
			<span class="kw1">return</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">affected_rows</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
		<span class="br0">&#125;</span>
	<span class="br0">&#125;</span>
&nbsp;
	<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">insert</span><span class="br0">&#40;</span><span class="re0">$tablename</span><span class="sy0">,</span><span class="re0">$data</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
	<span class="kw1">return</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">affected_rows</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="br0">&#125;</span>
&nbsp;
<span class="kw2">function</span> search<span class="br0">&#40;</span><span class="re0">$conditions</span><span class="sy0">=</span><span class="kw4">NULL</span><span class="sy0">,</span><span class="re0">$tablename</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span><span class="sy0">,</span><span class="re0">$limit</span><span class="sy0">=</span>500<span class="sy0">,</span><span class="re0">$offset</span><span class="sy0">=</span>0<span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$tablename</span><span class="sy0">==</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
	<span class="br0">&#123;</span>
		<span class="re0">$tablename</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">table</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
	<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$conditions</span> <span class="sy0">!=</span> <span class="kw4">NULL</span><span class="br0">&#41;</span>
		<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">where</span><span class="br0">&#40;</span><span class="re0">$conditions</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
	<span class="re0">$query</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">get</span><span class="br0">&#40;</span><span class="re0">$tablename</span><span class="sy0">,</span><span class="re0">$limit</span><span class="sy0">,</span><span class="re0">$offset</span><span class="sy0">=</span>0<span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">return</span> <span class="re0">$query</span><span class="sy0">-&gt;</span><span class="me1">result</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw2">function</span> insert<span class="br0">&#40;</span><span class="re0">$data</span><span class="sy0">,</span><span class="re0">$tablename</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$tablename</span><span class="sy0">==</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
		<span class="re0">$tablename</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">table</span><span class="sy0">;</span>
	<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">insert</span><span class="br0">&#40;</span><span class="re0">$tablename</span><span class="sy0">,</span><span class="re0">$data</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">return</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">affected_rows</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw2">function</span> update<span class="br0">&#40;</span><span class="re0">$data</span><span class="sy0">,</span><span class="re0">$conditions</span><span class="sy0">,</span><span class="re0">$tablename</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$tablename</span><span class="sy0">==</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
		<span class="re0">$tablename</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">table</span><span class="sy0">;</span>
	<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">where</span><span class="br0">&#40;</span><span class="re0">$conditions</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">update</span><span class="br0">&#40;</span><span class="re0">$tablename</span><span class="sy0">,</span><span class="re0">$data</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">return</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">affected_rows</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="kw2">function</span> delete<span class="br0">&#40;</span><span class="re0">$conditions</span><span class="sy0">,</span><span class="re0">$tablename</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	<span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$tablename</span><span class="sy0">==</span><span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>
		<span class="re0">$tablename</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">table</span><span class="sy0">;</span>
	<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">where</span><span class="br0">&#40;</span><span class="re0">$conditions</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">delete</span><span class="br0">&#40;</span><span class="re0">$tablename</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">return</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">db</span><span class="sy0">-&gt;</span><span class="me1">affected_rows</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>&nbsp;</p>
<p>After adding above 4 methods, using our Model class is easy. Just create a model by inheriting the new model class. Below is an example class and described the usage below the coding.</p>
<p>&nbsp;</p>
<div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span> <span class="kw1">if</span> <span class="br0">&#40;</span> <span class="sy0">!</span> <a href="http://www.php.net/defined"><span class="kw3">defined</span></a><span class="br0">&#40;</span><span class="st_h">'BASEPATH'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <a href="http://www.php.net/exit"><span class="kw3">exit</span></a><span class="br0">&#40;</span><span class="st_h">'No direct script access allowed'</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw2">class</span> Samlpe <span class="kw2">extends</span> MY_Model
<span class="br0">&#123;</span>
	<span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="br0">&#41;</span>
	<span class="br0">&#123;</span>
		parent<span class="sy0">::</span>__construct<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>&nbsp;</p>
<p>We have defined the Model class without any methods in it, and see below how we can use it in a controller.</p>
<p>$this-&gt;load-&gt;model(&#8220;Sample&#8221;);</p>
<p>$condition['id'] = &#8217;1&#8242;;</p>
<p>$this-&gt;sample-&gt;delete($condition); //Delete from Sample table, if same as class name then no need to pass table name</p>
<p>$this-&gt;sample-&gt;delete($condition,&#8221;AnotherTable&#8221;); //If delete from some other table</p>
<p>$data['fieldName'] = &#8216;field value&#8217;;</p>
<p>$data['fieldName2'] = &#8216;field value 2&#8242;</p>
<p>$this-&gt;sample-&gt;save($data);</p>
<p>I think this helped you in speeder development of Codeigniter PHP coding, next time will come up with some other tricks.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.betterhelpworld.com/codeigniter/a-smart-codeigniter-model/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to use Facebook PHP SDK v.3.0.0 with Codeigniter?</title>
		<link>http://www.betterhelpworld.com/codeigniter/how-to-use-facebook-php-sdk-v-3-0-0-with-codeigniter</link>
		<comments>http://www.betterhelpworld.com/codeigniter/how-to-use-facebook-php-sdk-v-3-0-0-with-codeigniter#comments</comments>
		<pubDate>Mon, 06 Jun 2011 17:50:08 +0000</pubDate>
		<dc:creator>msnisha</dc:creator>
				<category><![CDATA[Codeigniter]]></category>

		<guid isPermaLink="false">http://www.betterhelpworld.com/?p=16</guid>
		<description><![CDATA[There is some changes has been done in the Facebook PHP SDK v.3.0.0. There is no more method named as getSession. So if you have updated to the new Fecebook PHP SDK then you might have to modify your Codeigniter Facebook connect library. You can follow these simple steps to have a working Codeigniter Facebook library....]]></description>
			<content:encoded><![CDATA[<p>There is some changes has been done in the Facebook PHP SDK v.3.0.0. There is no more method named as getSession. So if you have updated to the new Fecebook PHP SDK then you might have to modify your Codeigniter Facebook connect library.</p>
<p>You can follow these simple steps to have a working Codeigniter Facebook library.</p>
<ol>
<li>Create a Config file in application/facebook.php with the following code in it.</li>
<div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="re0">$config</span><span class="br0">&#91;</span><span class="st_h">'appId'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'Your Facebook App ID'</span><span class="sy0">;</span>
<span class="re0">$config</span><span class="br0">&#91;</span><span class="st_h">'secret'</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st_h">'Your secret Code'</span><span class="sy0">;</span></pre></div></div>
<li>There is two files provided starting from V.3.0.0 of Facebook PHP SDK. Create a folder in application library and name it as facebook.</li>
<li>Download the Facebook PHP SDK files and place it in the folder application/library/facebook. You can download it from <a href="https://github.com/facebook/php-sdk">https://github.com/facebook/php-sdk</a></li>
<li>Create a new file and name it as fb_connect.php in application/library and copy the following code inside that folder. <div id="wpshdo_10" class="wp-synhighlighter-outer"><div id="wpshdt_10" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_10"></a><a id="wpshat_10" class="wp-synhighlighter-title" href="#codesyntax_10"  onClick="javascript:wpsh_toggleBlock(10)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_10" onClick="javascript:wpsh_code(10)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_print(10)" title="Print code"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_10" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">&lt;?php</span>
	<span class="kw1">include</span><span class="br0">&#40;</span>APPPATH<span class="sy0">.</span><span class="st_h">'libraries/facebook/facebook.php'</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
	<span class="kw2">class</span> Fb_connect <span class="kw2">extends</span> Facebook<span class="br0">&#123;</span>
&nbsp;
		<span class="co1">//declare public variables</span>
		<span class="kw2">public</span> 	<span class="re0">$user</span> 			<span class="sy0">=</span> <span class="kw4">NULL</span><span class="sy0">;</span>
		<span class="kw2">public</span> 	<span class="re0">$user_id</span> 		<span class="sy0">=</span> <span class="kw4">FALSE</span><span class="sy0">;</span>
&nbsp;
		<span class="kw2">public</span> <span class="re0">$fb</span> 			<span class="sy0">=</span> <span class="kw4">FALSE</span><span class="sy0">;</span>
		<span class="kw2">public</span> <span class="re0">$fbSession</span>	<span class="sy0">=</span> <span class="kw4">FALSE</span><span class="sy0">;</span>
		<span class="kw2">public</span> <span class="re0">$appkey</span>		<span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span>
&nbsp;
		<span class="co1">//constructor method.</span>
		<span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="br0">&#41;</span>
		<span class="br0">&#123;</span>
                    <span class="re0">$CI</span> <span class="sy0">=</span> <span class="sy0">&amp;</span> get_instance<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
                    <span class="re0">$CI</span><span class="sy0">-&gt;</span><span class="me1">config</span><span class="sy0">-&gt;</span><span class="me1">load</span><span class="br0">&#40;</span><span class="st0">&quot;facebook&quot;</span><span class="sy0">,</span><span class="kw4">TRUE</span><span class="br0">&#41;</span><span class="sy0">;</span>
                    <span class="re0">$config</span> <span class="sy0">=</span> <span class="re0">$CI</span><span class="sy0">-&gt;</span><span class="me1">config</span><span class="sy0">-&gt;</span><span class="me1">item</span><span class="br0">&#40;</span><span class="st_h">'facebook'</span><span class="br0">&#41;</span><span class="sy0">;</span>
                    parent<span class="sy0">::</span>__construct<span class="br0">&#40;</span><span class="re0">$config</span><span class="br0">&#41;</span><span class="sy0">;</span>
                    <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">user_id</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">getUser</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// New code</span>
&nbsp;
                    <span class="re0">$me</span> <span class="sy0">=</span> <span class="kw4">null</span><span class="sy0">;</span>
                    <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">user_id</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                        try <span class="br0">&#123;</span>
                            <span class="re0">$me</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">api</span><span class="br0">&#40;</span><span class="st_h">'/me'</span><span class="br0">&#41;</span><span class="sy0">;</span>
                            <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">user</span> <span class="sy0">=</span> <span class="re0">$me</span><span class="sy0">;</span>
                            <span class="br0">&#125;</span> catch <span class="br0">&#40;</span>FacebookApiException <span class="re0">$e</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                                <a href="http://www.php.net/error_log"><span class="kw3">error_log</span></a><span class="br0">&#40;</span><span class="re0">$e</span><span class="br0">&#41;</span><span class="sy0">;</span>
                            <span class="br0">&#125;</span>
			<span class="br0">&#125;</span>
		<span class="br0">&#125;</span> 
&nbsp;
	<span class="br0">&#125;</span> <span class="co1">// end class</span></pre></div></div></pre>
</li>
</ol>
<p><span style="font-size: 12px; line-height: 12px;">Now create a Controller and name it as user, and write the following methods in it.</span></p>
<pre>  <div id="wpshdo_11" class="wp-synhighlighter-outer"><div id="wpshdt_11" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_11"></a><a id="wpshat_11" class="wp-synhighlighter-title" href="#codesyntax_11"  onClick="javascript:wpsh_toggleBlock(11)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_11" onClick="javascript:wpsh_code(11)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_11" onClick="javascript:wpsh_print(11)" title="Print code"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_11" class="wp-synhighlighter-inner" style="display: block;"><pre class="php" style="font-family:monospace;"><span class="kw2">function</span> loginByFacebook<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
        	<span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">load</span><span class="sy0">-&gt;</span><span class="me1">library</span><span class="br0">&#40;</span><span class="st_h">'fb_connect'</span><span class="br0">&#41;</span><span class="sy0">;</span>
	        <span class="re0">$param</span><span class="br0">&#91;</span><span class="st_h">'redirect_uri'</span><span class="br0">&#93;</span><span class="sy0">=</span>site_url<span class="br0">&#40;</span><span class="st0">&quot;user/facebook&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	        redirect<span class="br0">&#40;</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">fb_connect</span><span class="sy0">-&gt;</span><span class="me1">getLoginUrl</span><span class="br0">&#40;</span><span class="re0">$param</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
&nbsp;
	<span class="kw2">function</span> facebook<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	        <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">load</span><span class="sy0">-&gt;</span><span class="me1">library</span><span class="br0">&#40;</span><span class="st_h">'fb_connect'</span><span class="br0">&#41;</span><span class="sy0">;</span>
	        <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">fb_connect</span><span class="sy0">-&gt;</span><span class="me1">user_id</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	            <span class="co1">//Handle not logged in,</span>
	        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
	           <span class="re0">$fb_uid</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">fb_connect</span><span class="sy0">-&gt;</span><span class="me1">user_id</span><span class="sy0">;</span>
	           <span class="re0">$fb_usr</span> <span class="sy0">=</span> <span class="re0">$this</span><span class="sy0">-&gt;</span><span class="me1">fb_connect</span><span class="sy0">-&gt;</span><span class="me1">user</span><span class="sy0">;</span>
	           <span class="co1">//Hanlde user logged in, you can update your session with the available data</span>
        	   <span class="co1">//print_r($fb_usr) will help to see what is returned</span>
	        <span class="br0">&#125;</span>
	<span class="br0">&#125;</span></pre></div></div></pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>That is all about the coding now when ever you need to login with facebook just redirect to user/loginByFacebook and your login will handled automatically by Facebook. But you need to update the facebook() method with the actions success and failure conditions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.betterhelpworld.com/codeigniter/how-to-use-facebook-php-sdk-v-3-0-0-with-codeigniter/feed</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Repopulate form fields in Codeigniter</title>
		<link>http://www.betterhelpworld.com/codeigniter/repopulate-form-fields-in-codeigniter</link>
		<comments>http://www.betterhelpworld.com/codeigniter/repopulate-form-fields-in-codeigniter#comments</comments>
		<pubDate>Sat, 04 Jun 2011 12:30:11 +0000</pubDate>
		<dc:creator>msnisha</dc:creator>
				<category><![CDATA[Codeigniter]]></category>
		<category><![CDATA[Form Validation]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.betterhelpworld.com/?p=6</guid>
		<description><![CDATA[&#160; I had some problems in repopulating the form POST values on the fields which are not used in the CI form validation. This is how I have solved it. When we use the set_value, if the form validation library is loaded then it looks for the value in the form validation library object. So...]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p><a href="http://www.betterhelpworld.com/wp-content/uploads/2011/06/codeigniter-logo.png"></a>I had some problems in repopulating the form POST values on the fields which are not used in the CI form validation. This is how I have solved it.</p>
<p>When we use the set_value, if the form validation library is loaded then it looks for the value in the form validation library object. So if you are not going to use any validation on the field, you can only load the form helper so that set_value work even if the field is not used in the validation.</p>
<p>But let say if you are doing validation on some fields then the above approach will not work. In that case you can set a dummy validation on the field as following.</p>
<p>$this-&gt;form_validation-&gt;set_rules(&#8220;field_name&#8221;,&#8221;Display Name&#8221;,&#8221;");</p>
<p>If you are not happy with the above indirect way, then you can overwrite the set_value function from the form helper class by following the steps below.</p>
<p>1) Create a file named MY_form_helper.php in helper folder. (application/helper)</p>
<p>2) Write down the following code in it.</p>
<p>&nbsp;</p>
<div id="wpshdo_12" class="wp-synhighlighter-outer"><div id="wpshdt_12" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_12"></a><a id="wpshat_12" class="wp-synhighlighter-title" href="#codesyntax_12"  onClick="javascript:wpsh_toggleBlock(12)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_12" onClick="javascript:wpsh_code(12)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_12" onClick="javascript:wpsh_print(12)" title="Print code"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.betterhelpworld.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_12" class="wp-synhighlighter-inner" style="display: block;"><div class="php" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="kw2">&lt;?php</span> <span class="kw1">if</span> <span class="br0">&#40;</span> <span class="sy0">!</span> <a href="http://www.php.net/defined"><span class="kw3">defined</span></a><span class="br0">&#40;</span><span class="st_h">'BASEPATH'</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <a href="http://www.php.net/exit"><span class="kw3">exit</span></a><span class="br0">&#40;</span><span class="st_h">'No direct script access allowed'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="co4">/**</span></div></li>
<li class="li1"><div class="de1"><span class="co4">* Form Value</span></div></li>
<li class="li1"><div class="de1"><span class="co4">*</span></div></li>
<li class="li1"><div class="de1"><span class="co4">* Grabs a value from the POST array for the specified field so you can</span></div></li>
<li class="li1"><div class="de1"><span class="co4">* re-populate an input field or textarea. &nbsp;If Form Validation</span></div></li>
<li class="li1"><div class="de1"><span class="co4">* is active it retrieves the info from the validation class</span></div></li>
<li class="li1"><div class="de1"><span class="co4">*</span></div></li>
<li class="li1"><div class="de1"><span class="co4">* @access &nbsp; public</span></div></li>
<li class="li1"><div class="de1"><span class="co4">* @param &nbsp; string</span></div></li>
<li class="li1"><div class="de1"><span class="co4">* @return &nbsp; mixed</span></div></li>
<li class="li1"><div class="de1"><span class="co4">*/</span></div></li>
<li class="li1"><div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span> <span class="sy0">!</span> <a href="http://www.php.net/function_exists"><span class="kw3">function_exists</span></a><span class="br0">&#40;</span><span class="st_h">'set_value'</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div></li>
<li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp; <span class="kw2">function</span> set_value<span class="br0">&#40;</span><span class="re0">$field</span> <span class="sy0">=</span> <span class="st_h">''</span><span class="sy0">,</span> <span class="re0">$default</span> <span class="sy0">=</span> <span class="st_h">''</span><span class="br0">&#41;</span></div></li>
<li class="li1"><div class="de1">&nbsp; <span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="re0">$OBJ</span> <span class="sy0">=&amp;</span> _get_validation_object<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$OBJ</span> <span class="sy0">===</span> <span class="kw4">TRUE</span> <span class="sy0">&amp;&amp;</span> <a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$OBJ</span><span class="sy0">-&gt;</span>_field_data<span class="br0">&#91;</span><span class="re0">$field</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> form_prep<span class="br0">&#40;</span><span class="re0">$OBJ</span><span class="sy0">-&gt;</span><span class="me1">set_value</span><span class="br0">&#40;</span><span class="re0">$field</span><span class="sy0">,</span> <span class="re0">$default</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw1">else</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> <span class="sy0">!</span> <a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="re0">$field</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$default</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> form_prep<span class="br0">&#40;</span><span class="re0">$_POST</span><span class="br0">&#91;</span><span class="re0">$field</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li>
<li class="li1"><div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div></li>
<li class="li1"><div class="de1">&nbsp; <span class="br0">&#125;</span></div></li>
<li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li>
<li class="li1"><div class="de1">&nbsp;</div></li>
<li class="li1"><div class="de1"><span class="coMULTI">/* End of file MY_form_helper.php */</span></div></li>
<li class="li1"><div class="de1"><span class="coMULTI">/* Location: ./application/helpers/MY_form_helper.php */</span></div></li>
</ol></div></div></div>
<p>&nbsp;</p>
<p>But in the last approach, you will have to rewrite all the helper functions based on the need basis. So it is better to go for the second one in case you need a validation on some fields otherwise go for the first approach.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.betterhelpworld.com/codeigniter/repopulate-form-fields-in-codeigniter/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

