RadoslavGeorgiev / rila-framework

A front-end WordPress framework with a set of many extendable class wrappers, inpired by the MVC ideology
GNU General Public License v2.0
18 stars 3 forks source link

Collection at method doesn't check #11

Closed JuhG closed 7 years ago

JuhG commented 7 years ago

Hey Rado,

a quick question to collections. This results in an error every time, because the items array is empty.

$collection = new \Rila\Collection\Posts(array(
    'post_type' => 'post'
));

if ( $post = $collection->at( 0 ) ) {
    // Do something
}

I was just wondering if I miss something or the at method should load the posts, otherwise the items array is empty. Also the if check doesn't do anything right now.

// class-collection.php

// now
public function at( $index ) {  
    return $this->items[ $index ];
}

// changes
public function at( $index ) {
    $this->check();

    if( ! isset( $this->items[ $index ] ) ) {
        return null;
    }

    return $this->items[ $index ];
}
RadoslavGeorgiev commented 7 years ago

Hi @JuhG,

this is fixed in 8600a8e6c93091db1601abfd1b6105e1029c7183.

As we discussed it in the ticket, I needed to improve a few things in the collections and as I mentioned it there, at was not implemented properly.

There will be a commit with shortcuts like rila_posts and etc. very soon.