1. Go to this page and download the library: Download tina4stack/tina4php 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/ */
tina4stack / tina4php example snippets
use Tina4\Router;
use Tina4\Request;
use Tina4\Response;
Router::get("/api/items", function (Request $request, Response $response) {
return $response(["items" => []], HTTP_OK);
});
Router::post("/api/webhook", function (Request $request, Response $response) {
return $response(["ok" => true], HTTP_OK);
})->noAuth();
class User extends \Tina4\ORM
{
public $tableName = "users";
public $primaryKey = "id";
public $softDelete = true;
public $id;
public $name;
public $email;
public $hasMany = [["Order" => "userId"]];
public $hasOne = [["Profile" => "userId"]];
public $belongsTo = [["Customer" => "customerId"]];
}
$user = new User($request);
$user->save();
$user->load("email = '[email protected]'");
$user->delete();
$users = (new User())->select("*", 100)->asArray();
use Tina4\FakeData;
$fake = new FakeData();
$fake->name(); // "Alice Johnson"
$fake->email(); // "[email protected]"
$fake->phone(); // "+1-555-0123"
$fake->address(); // "123 Main St, Springfield"
$fake->paragraph(); // Lorem ipsum...
use Tina4\Messenger;
$messenger = new Messenger();
$messenger->sendEmail(
"[email protected]",
"Subject Line",
"<h1>Hello</h1><p>Message body</p>"
);
$container = new \Tina4\Container();
$container->singleton('db', fn() => Database::create(getenv('DB_URL')));
$container->register('mailer', fn() => new MailService());
$db = $container->get('db'); // same instance every time
$mailer = $container->get('mailer'); // new instance each time
/**
* @tests
* assert (1,1) === 2, "1 + 1 = 2"
* assert is_integer(1,1) === true, "This should be an integer"
*/
function add($a, $b) {
return $a + $b;
}
use Tina4\I18n;
$i18n = new I18n('en');
echo $i18n->translate("welcome.message", ["name" => "Alice"]);