CArrayDataProvider takes an array of AR models for being used in an zii Widget like CListView.
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.1 or above
Installation ¶
- Extract the release file under
protected/extensions
Usage ¶
See the following code example:
Yii::import('application.extensions.CArrayDataProvider');
$posts = User->posts;
$dataProvider=new CArrayDataProvider('Post', $posts);
// $dataProvider->getData() will return a list of Post objects belonging to User
Change Log ¶
December 19, 2009 ¶
- Initial release.
Deprecated?
An implementation of this with the same name is now included in the core as of 1.1.4
Pretty easy changeover:
Whereas with this extension I used the following:
$contactsDP = new CArrayDataProvider('Contacts', $this->model->contacts);
This can now be simplified to
$contactsDP = new CArrayDataProvider($this->model->contacts);
Sorting handling
Nice extension, but there's an update for this extension to sort by column: ex sort by posts or by categories.
Thanks
Change fetchKeys
if you don't have key equal to 0, you fetchKeys will not work. Please change it into following
protected function fetchKeys() { foreach( current($this->dataArray) as $key => $value ) $keys[] = $key; return $keys; }
Great
Cheers, exactly what I was after :)
Added Pagination handling.
I have modified this to handle pagination correctly.
protected function fetchData()
{
if( ( $pagination=$this->getPagination())!==false) { $pagination->setItemCount($this->getTotalItemCount()); $offset = $pagination->getOffset(); $limit = $pagination->getLimit(); return array_slice( $this->dataArray, $offset, $limit ); }
return $this->dataArray;
Mmm
I use WinRAR and it couldn't extract bz2 :)
Just added a .zip version
Just added a .zip version
but afaik winzip as winrar can extract .bz2 files under windows... :)
Not popular format
Not so popular format for the downloaded file (bz2) on not-*nix platforms, please use a more supported format (at least "gz" if not "zip").
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.