11 New User Notifications
Select a tab above to activate This blank page message helps protect your privacy, or you can show the first message here automatically through settings page
- Melissa Ayre INBOX Re: New security codes Hello again and thanks for being part... 56 seconds ago
- Adison Lee Msed quia non numquam eius 2 minutes ago
- Oliver Kopyuv Msed quia non numquam eius 3 days ago
- Dr. John Cook PhD Msed quia non numquam eius 2 weeks ago
- Sarah McBrook Msed quia non numquam eius 3 weeks ago
- Anothony Bezyeth Msed quia non numquam eius one month ago
- Lisa Hatchensen Msed quia non numquam eius one year ago
-
Administrator UPDATE System updated to version 4.6.3 (patch notes) 5 mins ago
-
Adison Lee replied to your video Cancer Drug Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day... 10 minutes ago
[your date here]
|
||||||
---|---|---|---|---|---|---|
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
30 | 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 | 1 | 2 | 3 |
2:30PM - Doctor's appointment
3:30PM - Report overview
4:30PM - Meeting with Donnah V.
5:30PM - Late Lunch
6:30PM - Report Compression
- SmartAdmin
- Database
- Introduction
Introduction
SmartAdmin's built-in Database functionalities. Learn more how \Models\Model
works.
Documentation
PHP Models
A library that allows you to easily create and define your models using PDO.
Installation
To enable Database functionality, include the init.db.php
file in your php script. You can also include this in the main init.php
file to initiate your database globally.
Follow the database installation guide if you need help configuring your database.
Usage
Model
The \Models\Model
class is a parent class that can be inherited to a Model class. Inheriting this class allows you to automatically map the result "row" into your model class (table). This class basically uses the PDO::FETC_INTO
style and made it easier for you. Here are the steps to link your table into a class:
Create your model class. For example, a User.php
class.
namespace Models;
class User extends Model {
public function getName() {
return $this->firstname.' '.$this->lastname;
}
}
Register your table to your custom Model
class.
// somewhere in your init.db.php
\Models\User::register('users');
Now, you can directly get the User
instance from a query. Example:
$user = \Models\User::query_row("SELECT id, name FROM users WHERE id = 1 AND active = 1");
// You can also do this
// 1 is the id (primary key)
$user = \Models\User::instance(1);
// you can call the get_name() method now
if ($user) {
$name = $user->getName();
echo 'His name is '.$name;
}
Queries
To query multiple rows of data, you can provide your own SQL to the query
method of the Model
. For example:
$users = \Models\User::select("SELECT * FROM users WHERE active = 1");
foreach ($users as $user) {
$name = $user->getName();
echo 'User #'.$user->id.' '.$name.'<br>';
}
You can pass the
$data
to the \Bootstrap\Components\Table
class to create a table. See PHP Components / Table page for more information.
Credits
SmartAdmin uses lodev09/php-models package to connect and CRUD your database. Created by @lodev09.