1. Go to this page and download the library: Download dawidgorecki/litemvc library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
public function before()
{
// e.g. checking authentication
if (!Session::userIsLoggedIn()) {
$errorController = new ErrorController();
$errorController->error403();
exit();
}
}
public function after()
{
// do something
}
$db = $this->getDB();
// Prepare a statement for execution
$db->prepare("SELECT title FROM pages WHERE id = :id LIMIT 1");
// Bind a value to a parameter
$db->bind("id", $id);
// Execute a prepared statement and return result set
return $db->executeAndFetchAll();
// INSERT INTO users(name,email) VALUES('John','[email protected]')
$user = new User();
$user->setName("John");
$user->setEmail("[email protected]");
$user->save();
// SELECT * FROM users WHERE id=1 LIMIT 1
$user = User::findById(1);
echo $user->getName();
// SELECT * FROM users
$users = User::findAll();
foreach ($users as $user) {
echo $user->getName();
}
// SELECT * FROM users WHERE email='[email protected]'
$users = User::findByQuery("SELECT * FROM users WHERE email=:email", [":email" => "[email protected]"]);
echo $users[0]->getName();
// UPDATE users SET name='Edwin' WHERE id=1
$user = User::findById(1);
$user->setName("Edwin");
$user->save();
// DELETE FROM users WHERE id=1
$user = User::findById(1);
$user->delete();
$rowCount = User::getRowsCount();
if (!CaptchaUtils::checkCaptcha($userInput)) {
// wrong captcha code
} else {
// code ok
}
$mailer = new Libraries\Core\Mail();
$mailer->addRecipient('[email protected]', 'John Doe');
$mailer->addContent('Subject', 'My message');
if ($mailer->sendMessage('[email protected]', 'Peter Doe')) {
// message was send
} else {
// error
die($mailer->getError());
}