Created
March 24, 2016 15:41
-
-
Save korniychuk/cb0267268550309f1cfb to your computer and use it in GitHub Desktop.
index articles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### 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