Yii3 - How to start

Comparing #21 with #22

Revision #22 was created by rackycz rackycz on Oct 9, 2025, 10:21:18 AM.

edit

Content

[...]
## 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));
 
```