-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
123 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,31 @@ | ||
Define your Model | ||
Define your Model: | ||
|
||
```php | ||
class MyModel extends \hiqdev\hiart\ActiveRecord | ||
class User extends \hiqdev\hiart\ActiveRecord | ||
{ | ||
public function attributes() | ||
public function rules() | ||
{ | ||
return ['id', 'name', 'else']; | ||
return [ | ||
['id', 'integer', 'min' => 1], | ||
['login', 'string', 'min' => 2, 'max' => 32], | ||
]; | ||
} | ||
} | ||
``` | ||
|
||
Note that you use general `hiqdev\hiart\ActiveRecord` class not specific for certain API. | ||
API is specified in connection options and you don't need to change model classes when | ||
you change API. | ||
|
||
Then you just use your models same way as DB ActiveRecord models. | ||
|
||
```php | ||
$user = new User(); | ||
$user->login = 'sol'; | ||
|
||
$user->save(); | ||
|
||
$admins = User::find()->where(['type' => User::ADMIN_TYPE])->all(); | ||
``` | ||
|
||
Basically all features of Yii ActiveRecords work if your API provides them. |