<?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>Georgi.Budinov.com &#187; YiiFramework</title>
	<atom:link href="http://georgi.budinov.com/category/programming/php/yiiframework/feed/" rel="self" type="application/rss+xml" />
	<link>http://georgi.budinov.com</link>
	<description>The sacred mission of a Web Developer - Get the job done!</description>
	<lastBuildDate>Wed, 02 Nov 2011 13:55:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>The CArrayDataProvider problem of Yii</title>
		<link>http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/</link>
		<comments>http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/#comments</comments>
		<pubDate>Sun, 18 Sep 2011 19:19:58 +0000</pubDate>
		<dc:creator>Georgi Budinov</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[YiiFramework]]></category>

		<guid isPermaLink="false">http://georgi.budinov.com/?p=921</guid>
		<description><![CDATA[Recently I started digging in the YiiFramework. The first things I want to know about the framework were the basics &#8211; how the MVC is accomplished, database connections, ready to use component and so on. As the development team is actually the team that was engaged with the Prado framework before, I assumed that Yii [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I started digging in the YiiFramework. The first things I want to know about the framework were the basics &#8211; how the MVC is accomplished, database connections, ready to use component and so on. As the development team is actually the team that was engaged with the Prado framework before, I assumed that Yii will be very similar which actually is not very true. Well I won&#8217;t talk now about all the stuff I noticed and I will go straight to one of the first things I got a little irritating.<br />
<span id="more-921"></span><br />
The thing is that all core components are bind or connected in some way to Active Records which is something I don&#8217;t use. That is a choice I have made and you can not sue me for that. I don&#8217;t like the concept and prefer to make my own queries &#8211; perhaps this is some for another post.</p>
<p>This is the case with the CArrayDataProvider. Actually they have CActiveDataProvider which is bind to AR and working like a charm. It is making two queries one with the data and one with the count of rows so you get a nice pagination component when using with a gridview or listview. Well this is not the case with CArrayDataProvider. They didn&#8217;t assume that someone like me would want to make himself the two queries and set the current page, total count of raws and pass the excerpt of them. What they actually do is using the array_slice method to get the needed portion of the page when using with a CPager. Well I can see that this has been done in the old ages. The component needs all the records from the database and will cut off the needed portion. This is insane. That is why I modified it a little bit &#8230; yeah it is almost nothing so it suits my needs. Just extend the CArrayDataProvider and include it.</p>
<pre class="brush: php;">
class ArrayDataProvider extends CArrayDataProvider
{
	/**
	 * Fetches the data from the persistent data storage.
	 * @return array list of data items
	 */
	protected function fetchData()
	{
		if(($sort=$this-&gt;getSort())!==false &amp;&amp; ($order=$sort-&gt;getOrderBy())!='')
			$this-&gt;sortData($this-&gt;getSortDirections($order));

		if(($pagination=$this-&gt;getPagination())!==false)
		{
			$pagination-&gt;setItemCount($this-&gt;getTotalItemCount());
			return $this-&gt;rawData;
			//return array_slice($this-&gt;rawData, $pagination-&gt;getOffset(), $pagination-&gt;getLimit());
		}
		else
			return $this-&gt;rawData;
	}
}
</pre>
<p>Usage:</p>
<pre class="brush: php;">
$viewData['dataProvider'] = new ArrayDataProvider(
			$array['rows'],
			array(
				'totalItemCount' =&gt; $array['count'],
				'pagination'=&gt;array(
					'pageSize' =&gt; 10,
				),
			)
		);
</pre>
<div class="social_bookmark"><script type="text/javascript"><!--
google_ad_client = "pub-1171831089941131";
google_ad_slot = "5499515740";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</div><!-- Social Bookmarking Reloaded BEGIN --><div class="social_bookmark"><em>Bookmark It</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/&amp;title=The+CArrayDataProvider+problem+of+Yii" title="Bookmark 'The CArrayDataProvider problem of Yii' in Del.icio.us"><img src="http://georgi.budinov.com/wp-content/plugins/social-bookmarking-reloaded/delicious.png" title="Bookmark 'The CArrayDataProvider problem of Yii' in Del.icio.us" alt="Bookmark 'The CArrayDataProvider problem of Yii' in Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/&amp;title=The+CArrayDataProvider+problem+of+Yii" title="Bookmark 'The CArrayDataProvider problem of Yii' in digg"><img src="http://georgi.budinov.com/wp-content/plugins/social-bookmarking-reloaded/digg.png" title="Bookmark 'The CArrayDataProvider problem of Yii' in digg" alt="Bookmark 'The CArrayDataProvider problem of Yii' in digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/" title="Bookmark 'The CArrayDataProvider problem of Yii' in Technorati"><img src="http://georgi.budinov.com/wp-content/plugins/social-bookmarking-reloaded/technorati.png" title="Bookmark 'The CArrayDataProvider problem of Yii' in Technorati" alt="Bookmark 'The CArrayDataProvider problem of Yii' in Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/&amp;t=The+CArrayDataProvider+problem+of+Yii" title="Bookmark 'The CArrayDataProvider problem of Yii' in Yahoo My Web"><img src="http://georgi.budinov.com/wp-content/plugins/social-bookmarking-reloaded/yahoo_myweb.png" title="Bookmark 'The CArrayDataProvider problem of Yii' in Yahoo My Web" alt="Bookmark 'The CArrayDataProvider problem of Yii' in Yahoo My Web" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/&amp;title=The+CArrayDataProvider+problem+of+Yii" title="Bookmark 'The CArrayDataProvider problem of Yii' in Google Bookmarks"><img src="http://georgi.budinov.com/wp-content/plugins/social-bookmarking-reloaded/google.png" title="Bookmark 'The CArrayDataProvider problem of Yii' in Google Bookmarks" alt="Bookmark 'The CArrayDataProvider problem of Yii' in Google Bookmarks" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="https://favorites.live.com/quickadd.aspx?url=http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/&amp;title=The+CArrayDataProvider+problem+of+Yii" title="Bookmark 'The CArrayDataProvider problem of Yii' in Live-MSN"><img src="http://georgi.budinov.com/wp-content/plugins/social-bookmarking-reloaded/live.png" title="Bookmark 'The CArrayDataProvider problem of Yii' in Live-MSN" alt="Bookmark 'The CArrayDataProvider problem of Yii' in Live-MSN" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/&amp;t=The+CArrayDataProvider+problem+of+Yii" title="Bookmark 'The CArrayDataProvider problem of Yii' in FaceBook"><img src="http://georgi.budinov.com/wp-content/plugins/social-bookmarking-reloaded/facebook.png" title="Bookmark 'The CArrayDataProvider problem of Yii' in FaceBook" alt="Bookmark 'The CArrayDataProvider problem of Yii' in FaceBook" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.myspace.com/Modules/PostTo/Pages/?t=The+CArrayDataProvider+problem+of+Yii&amp;c=http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/" title="Bookmark 'The CArrayDataProvider problem of Yii' in MySpace"><img src="http://georgi.budinov.com/wp-content/plugins/social-bookmarking-reloaded/myspace.png" title="Bookmark 'The CArrayDataProvider problem of Yii' in MySpace" alt="Bookmark 'The CArrayDataProvider problem of Yii' in MySpace" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/" title="Bookmark 'The CArrayDataProvider problem of Yii' in Twitter"><img src="http://georgi.budinov.com/wp-content/plugins/social-bookmarking-reloaded/twitter.png" title="Bookmark 'The CArrayDataProvider problem of Yii' in Twitter" alt="Bookmark 'The CArrayDataProvider problem of Yii' in Twitter" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://friendfeed.com/share/bookmarklet/frame#title=The+CArrayDataProvider+problem+of+Yii&amp;url=http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/" title="Bookmark 'The CArrayDataProvider problem of Yii' in FriendFeed"><img src="http://georgi.budinov.com/wp-content/plugins/social-bookmarking-reloaded/friendfeed.png" title="Bookmark 'The CArrayDataProvider problem of Yii' in FriendFeed" alt="Bookmark 'The CArrayDataProvider problem of Yii' in FriendFeed" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/reader/link?url=http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/&amp;title=The+CArrayDataProvider+problem+of+Yii&amp;srcURL=http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/" title="Bookmark 'The CArrayDataProvider problem of Yii' in Google Buzz"><img src="http://georgi.budinov.com/wp-content/plugins/social-bookmarking-reloaded/googlebuzz.png" title="Bookmark 'The CArrayDataProvider problem of Yii' in Google Buzz" alt="Bookmark 'The CArrayDataProvider problem of Yii' in Google Buzz" /></a></div>
<!-- Social Bookmarking Reloaded END -->]]></content:encoded>
			<wfw:commentRss>http://georgi.budinov.com/2011/09/the-carraydataprovider-problem-of-yii/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

