Commit a948e738 by Alexander Makarov

example for using asArray

parent 03cd47ae
...@@ -147,9 +147,28 @@ A good way to save memory and processing time on read-only pages is to use ...@@ -147,9 +147,28 @@ A good way to save memory and processing time on read-only pages is to use
ActiveRecord's `asArray` method. ActiveRecord's `asArray` method.
```php ```php
class PostController extends Controller
{
public function actionIndex()
{
$posts = Post::find()->orderBy('id DESC')->limit(100)->asArray()->all();
echo $this->render('index', array(
'posts' => $posts,
));
}
}
``` ```
TBD In the view you should access fields of each invidual record from `$posts` as array:
```php
foreach($posts as $post) {
echo $post['title']."<br>";
}
```
Note that you can use array notation even if `asArray` wasn't specified and you're
working with AR objects.
### Processing data in background ### Processing data in background
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment