Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace common\models;
- class ProductModel // вообще тут должно быть 'extends \yii\db\ActiveRecord'
- {
- public $mockProducts = array( // начиная с этой строки идет живой пример того, как НЕ надо писать реальную модель. Все написанное здесь написано исключительно ради примера.
- array('id' => 1, 'title' => 'CodeIgniter', 'description' => 'Quite popular framework from previous decade',),
- array('id' => 2, 'title' => 'Symfony', 'description' => 'A framework that promotes organizing everything in reusable bundles',),
- array('id' => 3, 'title' => 'Yii', 'description' => 'Framework that attracts developers by it\'s simplicity',),
- );
- public function get($id)
- {
- $id = (int) $id;
- if ($id < 1) {
- throw new \InvalidArgumentException('Invalid ID provided');
- }
- foreach ($this->mockProducts as $product) {
- if ($product['id'] === $id) {
- return $product;
- }
- }
- return false;
- }
- public function productExists($id)
- {
- foreach ($this->mockProducts as $product) {
- if ($product['id'] === $id) {
- return true;
- }
- }
- return false;
- }
- public function getAll()
- {
- return $this->mockProducts;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement