PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Jun 24, 2019 9:35 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sun Feb 28, 2010 12:52 pm 
Offline
Forum Newbie

Joined: Tue May 06, 2008 2:55 am
Posts: 10
hii all..

I want to ask.. how to pagination data in array with zend framework ?
If pagination data from tabel in database, that's work fine, but if I create my own data in array, it's not working..
this is my example code:
> in model:
Syntax: [ Download ] [ Hide ]
public function getFolder() {
        if(!($open = opendir($this->folder))) {
            die("Cannot open directory..!!");
        }
       
        $result = array();
        $n = 0;
        while($folder = readdir($open)) {
            if(is_dir($this->folder . $folder) == true) {
                if($folder <> "." and $folder <> "..") {
                    $result[$n]['foldername'] = $folder;
                    $n += 1;
                }
            }
        }
        closedir($open);
       
        return $result;
    }


> in controller:
Syntax: [ Download ] [ Hide ]
public function galleryAction() {
        $currentPage = $this->_request->getParam('page', 1);
        $folder = "pictures/gallery/";
       
        $PicturesManager = new Default_Model_PicturesManager();
        $PicturesManager->folder = $folder;
        $folders = $PicturesManager->getFolder();
       
        //Initialize the Zend_Paginator
        $paginator = Zend_Paginator::factory($folders);
       
        //Set the properties for the pagination
        $paginator->setItemCountPerPage(20);
        $paginator->setPageRange(10);
        $paginator->setCurrentPageNumber($currentPage);
       
        $this->view->folders = $paginator;
    }


> in view:
Syntax: [ Download ] [ Hide ]
if(is_array($this->folders)) {
    foreach($this->folders as $folder) {
        echo $folder[''foldername] ."<br>";
    }
} else {
    echo "empty";
}


can anybody help me ? thanks before.. :D


Top
 Profile  
 
PostPosted: Sun Feb 28, 2010 3:12 pm 
Offline
DevNet Resident
User avatar

Joined: Thu May 14, 2009 3:00 pm
Posts: 1011
Location: HellCity, Bulgaria
Are you sure the $result array is not empty?
By the way you have to use:
Syntax: [ Download ] [ Hide ]
while(($folder = readdir($open)) !== false) {



Edit:
what is the value of $this->folder? Does it have trailing slash? Without / at the end, this won't work :)


Top
 Profile  
 
PostPosted: Mon Mar 01, 2010 11:33 am 
Offline
Forum Newbie

Joined: Tue May 06, 2008 2:55 am
Posts: 10
Darhazer wrote:
Are you sure the $result array is not empty?

I'm sure it's not empty.. the result is the list name of all folder that exist.. if i'm not use pagination control, it work fine.. but when I use pagination control, it doesn't show anything..

Darhazer wrote:
By the way you have to use:
Syntax: [ Download ] [ Hide ]
while(($folder = readdir($open)) !== false) {

ok2.. thanks for the advise..

Darhazer wrote:
Edit:
what is the value of $this->folder? Does it have trailing slash? Without / at the end, this won't work :)

$this->folder = "pictures/gallery/";


Top
 Profile  
 
PostPosted: Mon Mar 01, 2010 1:45 pm 
Offline
DevNet Resident
User avatar

Joined: Thu May 14, 2009 3:00 pm
Posts: 1011
Location: HellCity, Bulgaria
wow, I just noticed that you are not using the paginator in your viewscript at all. I thought that your paginator works with data from database but not with array. It seems that your viewscript works without paginator, but not with the paginator.

Syntax: [ Download ] [ Hide ]
echo $this->partialLoop('partials/folder.phtml', $this->paginator);
echo $this->paginationControl($this->paginator, 'Sliding', 'partials/pagination.phtml');
 

partials/folders.phtml:
Syntax: [ Download ] [ Hide ]
<?php echo $this->foldername; ?>


Btw I've just noticed another error in your viewscript:
echo $folder[''foldername] ."<br>";
should be
echo $folder['foldername'] ."<br>";


Top
 Profile  
 
PostPosted: Sun Mar 14, 2010 5:42 am 
Offline
Forum Newbie

Joined: Tue May 06, 2008 2:55 am
Posts: 10
the problem is fix now..

thanks for the help.. :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group