Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save korniychuk/cb0267268550309f1cfb to your computer and use it in GitHub Desktop.
Save korniychuk/cb0267268550309f1cfb to your computer and use it in GitHub Desktop.
index articles
#### model:
```php
class Article extends ActiveRecord {
public static tableName() {
return 'article';
}
}
```
#### controller:
```php
class SiteController extends Controller {
....
public function actionIndex()
{
$articles = Article::find()->orderBy('created_at DESC')->all();
return $this->render('index', [
'articles' => $articles,
]);
}
....
}
```
#### view:
foreach($articles as $one) {
...
<?=$one->title?>
...
}
#### Один нюанс - нужна пагинация.
Тут поможет ActiveDataProvider и Pagination
Посмотрите эти ссылки:
http://stackoverflow.com/questions/23336269/how-to-create-pager-in-yii2
http://docs.mirocow.com/doku.php?id=yii2:activedataprovider
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment