2017 © Pedro Peláez
 

windwalker-package model

Windwalker Model package

image

windwalker/model

Windwalker Model package

  • Friday, February 12, 2016
  • by asika32764
  • Repository
  • 3 Watchers
  • 0 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 24 Versions
  • 0 % Grown

The README.md

Windwalker Model

Windwalker Model provides an abstract interface to build your own model logic., (*1)

Installation via Composer

Add this to the require block in your composer.json., (*2)

``` json { "require": { "windwalker/model": "~2.0" } }, (*3)


## Create Model Extends the AbstractModel to create your own model. ``` php use Windwalker\Model\AbstractModel class MyModel extends AbstractModel { public function getItem() { return new stdClass; } } $model = new MyModel; $item = $model->getItem();

Database Model

Implements the DatabaseModelInterface, we will able to get and set a DB object to access database., (*4)

Windwalker Model do not dependency to any Database package, you can integrate your favorite data source to get data., (*5)

``` php use Windwalker\Model\AbstractModel use Windwalker\Model\DatabaseModelInterface;, (*6)

class MyModel extends AbstractModel implements DatabaseModelInterface { protected $db;, (*7)

public function __construct($db, Registry $state = null)
{
    $this->db = $db;

    parent::__construct($state);
}

public function getDb()
{
    return $this->db;
}

public function setDb($db)
{
    $this->db = $db;
}

public function getList()
{
    $this->db->setQuery('select * from users');

    return $this->db->loadAll();
}

}, (*8)


## Model State Model maintains their own state that we can change this state to get different data. ``` php class MyModel extends AbstractModel implements DatabaseModelInterface { // ... public function getUsers() { $published = $this->state->get('where.published', 1); $ordering = $this->state->get('list.ordering', 'id'); $direction = $this->state->get('list.direction', 'ASC'); $sql = "SELECT * FROM users " . " WHERE published = " . $published . " ORDER BY " . $ordering . " " . $direction; try { return $this->db->setQuery($sql)->loadAll(); } catch (\Exception $e) { $this->state->set('error', $e->getMessage()); return false; } } } $model = new MyModel; $state = $model->getState(); // Let's change model state $state->set('where.published', 1); $state->set('list.ordering', 'birth'); $state->set('list.direction', 'DESC'); $users = $model->getUsers(); if (!$users) { $error = $state->get('error'); }

Simple Way to Access State

Using get() and set(), (*9)

``` php // Same as getState()->get(); $model->get('where.author', 5);, (*10)

// Same as getState()->set(); $model->set('list.ordering', 'RAND()');, (*11)


### State ArrayAccess ``` php // Same as getState()->get(); $data = $model['list.ordering']; // Same as getState()->set(); $model['list.ordering'] = 'created_time';

The Versions

12/02 2016

dev-master

9999999-dev https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

12/02 2016

dev-test

dev-test https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

12/02 2016

2.1.7

2.1.7.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

12/02 2016

2.1.8

2.1.8.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

12/02 2016

2.1.9

2.1.9.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

11/08 2015

2.1

2.1.0.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

11/08 2015

2.1.1

2.1.1.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

11/08 2015

2.1.2

2.1.2.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

11/08 2015

2.1.4

2.1.4.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

11/08 2015

2.1.5

2.1.5.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

11/08 2015

2.1.6

2.1.6.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

27/07 2015

2.0.9

2.0.9.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

16/12 2014

2.0.0

2.0.0.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

16/12 2014

2.0.1

2.0.1.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

16/12 2014

2.0.2

2.0.2.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

16/12 2014

2.0.3

2.0.3.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

16/12 2014

2.0.4

2.0.4.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

16/12 2014

2.0.5

2.0.5.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

16/12 2014

2.0.6

2.0.6.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

16/12 2014

2.0.7

2.0.7.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

16/12 2014

2.0.8

2.0.8.0 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

25/11 2014

2.0.0-beta2

2.0.0.0-beta2 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

LGPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

05/10 2014

2.0.0-alpha

2.0.0.0-alpha https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework model windwalker

05/10 2014

2.0.0-beta1

2.0.0.0-beta1 https://github.com/ventoviro/windwalker-model

Windwalker Model package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework model windwalker