Iris is a PHP-Framework created to make building websites easy, without requiring extensive knowledge or the need to learn a complex new PHP-Framework.
โจ Key Features:
- ๐ Fast & Easy to set up
- ๐งฉ Just implement your controllers, views, and models
- ๐ Link pre-built functions to your controllers
- ๐ Error logging system, local or in database
- โ๏ธ Easy to enable functions via config file
- ๐งญ Built-in page router (check wiki for editing instructions)
- ๐ Built-in hashing classes and other security functions
- ๐จ Advanced error handler
- ๐๏ธ Built-in PDO style database handler
- ๐จ Built-in Twig view handler for designing your application layout with HTML
- ๐ค Built-in AI functions (OpenAI & Claude AI)
- ๐ฎ More to come...
Iris uses Twig to handle views in your application, allowing you to use your own HTML.
To get started, edit the 'base.html' file in the Views folder. This will be the base of your application.
To change the title of the window when navigating pages, use the following title tag in your HTML head:
<title>{% block title %}{% endblock %}</title>In the body tag, include the following code (recommended to put it after the navigation bar and before any JS scripts):
{% block body %}{% endblock %}- Create a folder named exactly like your website page (e.g., 'Home') in the Views folder.
- Add an index.html file to this folder with the following code:
{% extends "base.html" %}
{% block title %} Dashboard {% endblock %}
{% block body %}
<p>I'm an HTML view</p>
{% endblock %}Create a 'Home.php' file in the Controller folder with the following structure:
<?php
namespace App\Controllers;
use \Core\View;
class Home extends \Core\Controller {
protected function before() {
return false;
}
protected function after() {
return false;
}
public function indexAction() {
View::renderTemplate('Home/index.html', [
'name' => 'Raphael',
'colours' => ['red', 'green', 'blue']
]);
}
}before(): Executes before page content is loaded (e.g., check if user is logged in).after(): Executes after page content has loaded (e.g., save user data to track time spent on a page).
Enable these functions by returning true, disable by returning false.
URL structure: http://localhost/dashboard/index
$router->add('{controller}/{action}');{controller}= dashboard{action}= index
Note: Add 'Action' to your PHP function names (e.g., indexAction, usersAction).
Use View::renderTemplate($path, $options);
$path: path to the view (e.g., 'Home/index.html')$options: array of data to pass to the HTML
{{ NAME_OF_ARRAY_ITEM }}-
Import the model in your controller:
use App\Models\Post;
-
Use the model in your controller action:
$users = Post::getAll(); View::renderTemplate('Posts/index.html', ['users' => $users]);
-
Create a model file (e.g., Post.php) in the models folder:
<?php
namespace App\Models;
use Core\Model;
use PDO;
class Post extends Model {
public static function getAll(): bool|array {
try {
$db = static::getDB();
$stmt = $db->query('SELECT * FROM members ORDER BY id');
return $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
}{% extends "base.html" %}
{% block title %} User lists {% endblock %}
{% block body %}
<h1>Users list</h1>
<p>Hello {{ name }} </p>
<ul>
{% for user in users %}
<li><h2>{{ user.name }}</h2> <p>{{ user.lastname }}</p></li>
{% endfor %}
</ul>
{% endblock %}First, set up your API keys in the Iris config file:
const OPEN_AI_API_KEY = "YOUR KEY HERE";
const OPEN_AI_ENDPOINT = "https://api.openai.com/v1/";
const OPEN_AI_DEFAULT_MODEL = "gpt-3.5-turbo";
const CLAUDE_AI_API_KEY = "YOUR KEY HERE";
const CLAUD_AI_ENDPOINT = "https://api.anthropic.com/v1/messages";Available functions:
- Text response
- Image generation
- Transcription
- Translation
- Analysis
- Code generation
Usage examples:
$textResponse = OpenAI::generateText("Tell me a joke about programming.");
$imageUrl = OpenAI::generateImage("A futuristic city with flying cars");
$transcription = OpenAI::transcribeAudio("/path/to/audio/file.mp3");
$translation = OpenAI::translateText("Hello, world!", "French");
$analysis = OpenAI::analyzeContent("Long text to be analyzed...");
$code = OpenAI::generateCode("Python", "Create a function that calculates the factorial of a number.");Available functions:
- Text response
- Translation
- Analysis
- Code generation
Usage examples:
$response = ClaudAI::generateResponse("Tell me a joke about programming.");
$analysis = ClaudAI::analyzeText("Long text to be analyzed...");
$translation = ClaudAI::translateText("Hello, world!", "French");
$code = ClaudAI::generateCode("Python", "Create a function that calculates the factorial of a number.");Enhanced Security class features:
- Secure random token generation
- Data encryption and decryption
- Modern password hashing and verification
- CSRF protection mechanisms
- Input sanitization to prevent XSS attacks
- Secure file naming
- Password strength checking
Usage examples:
$token = Security::generateRandomToken();
$encryptedData = Security::encryptData('sensitive data', 'secret_key');
$decryptedData = Security::decryptData($encryptedData, 'secret_key');
$passwordHash = Security::hashPassword('user_password');
$isPasswordValid = Security::verifyPassword('user_password', $passwordHash);
$csrfToken = Security::generateCSRFToken();
$sanitizedInput = Security::sanitizeInput($_POST['user_input']);
$secureFilename = Security::generateSecureFileName('user_upload.jpg');
$isStrong = Security::isStrongPassword('User@Password123');example:
$google = new Google('path/to/client_secret.json');
// For the first-time use, you'll need to authenticate:
$authUrl = $google->getAuthUrl(['https://www.googleapis.com/auth/drive.file', 'https://www.googleapis.com/auth/calendar']);
// Redirect the user to $authUrl, then exchange the received code for an access token:
$accessToken = $google->fetchAccessTokenWithAuthCode($authCode);
$google->setAccessToken($accessToken);
// Now you can use the API functions:
$location = $google->geocode('1600 Amphitheatre Parkway, Mountain View, CA');
$files = $google->listDriveFiles();
$events = $google->listCalendarEvents();
$sheetData = $google->readSheetData('spreadsheetId', 'Sheet1!A1:B10');๐ With these features and examples, you're ready to build powerful and secure web applications using the Iris Framework!