This repository has been archived by the owner on May 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
README
137 lines (85 loc) · 3.35 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Diggriola
=========
Abstraction layer for Models between Nette & NotORM.
Complete tutorial in Slovak language can be found at http://wiki.nette.org/cs/cookbook/jednoduchy-model-s-notorm
Diggriola is simple layer for accesing (loading) Models in Nette Framework.
It is using excellent library NotORM by Jakub Vrána for database abstraction.
With usage of Nette's DI implementation, obtaining of Model instance
and table resultset is simple as:
final class FooPresenter extends BasePresenter {
public function renderDefault() {
$model = $this->getModel('application');
$applications = $model->findByAuthorName('John Doe');
}
}
Resultset can be iterated:
foreach ($applications as $app) {
echo "$app[name]: ";
foreach ($app->applications_tags() as $application_tag) { // M:N tags
echo "{$application_tag->tag['name']}, ";
}
echo '<br>';
}
All Models must inherit from Diggriola\BaseModel and be in Model namespace!
Installation
------------
- put Diggriola folder to your LIBS_DIR
- register services in app/config.neon
common:
services:
modelLoader:
class: Diggriola\ModelLoader
arguments: ['@dbConnection']
dbConnection:
factory: Diggriola\ModelLoader::dbConnect
- setup DB connection in app/config.neon
development < common:
database:
driver: mysql
host: localhost
database: nette_notorm
username: php
password: php
profiler: true
- write method for obtaining Models in BasePresenter
abstract class BasePresenter extends \Nette\Application\UI\Presenter {
protected function getModel($model) {
return $this->context->modelLoader->getModel($model);
}
}
- create model representing DB table
<?php
namespace Model;
class Application extends \Diggriola\BaseModel {
}
- setup session in app/bootstrap.php
$configurator->container->session->setExpiration('+ 90 days');
$configurator->container->session->start();
Thats it! Now you can enjoy Diggriola Models
Model API
---------
- <NotORM_Result> Diggrila\BaseModel::findBy<Column>(<column value>)
example: $applications = $applicationModel->findByName('Firefox');
- <NotORM_Result> Diggrila\BaseModel::findBy<Related table><Column>(<column value>)
example: $applications = $applicationModel->findByAuthorName('John Doe');
- <NotORM_Result> Diggrila\BaseModel::findBy<Related table><Column>(<column value>, true)
example: $applications = $applicationModel->findByTagName('php', true);
- <NotORM_Row> Diggrila\BaseModel::insert(<data array>)
example: $applicationModel->insert(array(
'name' => 'calc 3000',
'author_id' => '5',
));
- Diggrila\BaseModel::update(<NotORM_Result>, <data array>)
example: $applications = $applicationModel->findByAuthorName('John Doe');
$affected = $applicationModel->update(applications, array('status'=>'unsupported'));
- Diggrila\BaseModel::delete(<NotORM_Result>)
example: $applications = $applicationModel->findByAuthorName('John Doe');
$affected = $applicationModel->delete(applications);
Feel free to introduce own API extensions by modifiing Diggriola\BaseModel in your applications :)
Requirements
------------
- PHP 5.3
- Nette Framework 2.0 beta or DEV for PHP 5.3
- NotORM (dev)
Feedback appreciated,
cheers, srigi :)