Revision #22 has been created by
rackycz on Oct 9, 2025, 10:21:18 AM with the memo:
edit
« previous (#21) next (#23) »
Changes
Title
unchanged
Yii3 - How to start
Category
unchanged
Tutorials
Yii version
unchanged
3.0
Tags
unchanged
Content
changed
[...]
## Using Repository and the Model class
Each entity should have its Model class and Repository class if you are storing it in DB. Have a look at the demo application "blog-api": https://github.com/yiisoft/demo
In my case the User model (file `src/Entity/User.php`) will only contain private attributes, setters and getters.
`UserRepository
` (placed in the same folder) may look like this to enable CRUD (compressed code):
```php[...]
}
}
```
Now you can modify `IndexAction` to contain this: (read above to understand details)
```php
// use App\Entity\UserRepository;
$userRepository = $container->get(UserRepository::class);
return $responseFactory->success($userRepository->findAll([], true));
```