You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And lets me explain something. There is nothing wrong with the use of global. If something must be used or accessed everywhere, then it makes a sense that this something is global. What are we skipping with global? Dependency injection, containers, and whatnot! The use of global is bad if we use GLOBAL for variables or objects that they must not be shared globally, for example, local variables. So the use of global is not as absolute. Only sith think in absolute We could use globally if it is used correctly. The 100% ban on the use of GLOBAL it's silly, and it's religion.
108
+
And lets me explain something. There is nothing wrong with the use of global. If something must be used or accessed everywhere, then it makes a sense that this something is global. What are we skipping with global? Dependency injection, containers, and whatnot! The use of global is bad if we use GLOBAL for variables or objects that they must not be shared globally, for example, local variables. So the use of global is not as absolute. Only Sith think in absolute 😁 We could use globally if it is used correctly. The 100% ban on the use of GLOBAL it's silly, and it's religion.
105
109
106
110
107
111
@@ -153,31 +157,31 @@ Or using a GUI
153
157
154
158
## 3-step Creation of the Repository Layer
155
159
156
-
The repository layer.
160
+
The repository layer.
157
161
158
162
In the root folder, let's create and execute the next code:
159
163
160
164
📜 /genrepo.php
161
165
166
+
It calls a simple method but this method is quite verbose and long.
,'ExampleTicketBase' // base class (for the database
175
+
,'eftec\exampleticket\repo' //namespace of the class repository
176
+
,__DIR__.'/repo' // folder of the class repository
177
+
);
168
178
```
169
179
170
-
The method render create an interface visual
171
-
172
-

173
-
174
-
We want to create a new class. So let's select all the information, database, user, password, etc. For input, write down our table (**tickets**). And for output, selects the operation **classcode**
180
+
Now, this method creates the next files
175
181
176
-
For namespace use the next one: **eftec\exampleticket\repo** that matches with the psr-4 and folder.
177
-
178
-
In the text area called **log**, it will generate a PHP code. Copy it and write a new file.
179
-
180
-
* 📜 /repo/TicketsRepo.php
182
+
* 📜 /repo/TicketsRepo.php **But only if the file does not exist!!**. If you want to replace it, then you must delete it manually (or set the argument **$forced** of the method **generateAllClasses()** to **true**). Why? The concept of this class is it could be edited, so if we modify this class, then the changes are keep even if we rebuild all the repositories.
183
+
* 📜 /repo/AbstractTicketsRepo.php It is the class contains all the definitions of the table tickets.
184
+
* 📜 /repo/ExampleTicketBase.php This class is common to all tables
181
185
182
186
Finally, you can delete 📜 /genrepo.php (optionally)
183
187
@@ -287,32 +291,18 @@ We use our global function database(). It uses prepared-statement (hence the Col
287
291
288
292
* function list() This method returns all tickets from the database. If the operation fails, then we store a message (inside the validation class).
289
293
290
-
291
-
```php
292
-
public static function list() {
293
-
try {
294
-
$tickets = pdoOne()->select('*')
295
-
->from('Tickets')
296
-
->toList(); // select * from tickets
297
-
} catch (\Exception $e) {
298
-
valid()->addMessage('ERRORINSERT','Unable to list. '.pdoOne()->lastError(),'error');
299
-
$tickets=[];
300
-
}
301
-
return $tickets;
302
-
}
303
-
```
304
-
305
294
### Considerations
306
295
307
-
* What if the database is down?. Then it will stop the execution of any code.
296
+
* What if the database is down?. Then it will stop the execution of our code.
308
297
* What if the operation fails?. Then it will store an error message.
309
298
* What if the user enters a malicious code?. The library uses prepared-statement, so the code is safe from malicious entries. For example: if the name of the ticket is O'hara, the system will work correctly.
310
299
311
300
So the security and stability of the system are ensured.
312
301
313
302
## 6 step - Views
314
-
Since we are using the library BladeOne, then we could use views (instead of duct & taping the html+php inside the same class.
303
+
Since we are using the library **BladeOne**, then we could use views (instead of duct & taping the html+php inside the same class.
315
304
In our case, we will use two views (for insert and list)
305
+
316
306
* 📜 /views/ticket/index
317
307
It is part of the view: (without using eftec/BladeOneHtml)
0 commit comments