İnkişaf Çərçivələri
Veb tətbiqləri qurmaq üçün kiçik bir iz buraxan yüngül PHP çərçivəsi
Kiçik iz (2MB), minimal xərc və yalnız əsas komponentlərin yüklənməsi ilə istisnai performans
Ağıllı defoltlarla demək olar ki, sıfır konfiqurasiya quraşdırması: mürəkkəb konfiqurasiya olmadan dərhal kodlaşdırmağa başlayın
Ehtiyaclarınıza uyğunlaşdırmaq azadlığı ilə MVC nümunəsini sərbəst izləyir: tam MVC və ya sadələşdirilmiş yanaşmadan istifadə edin
XSS filtrasiyası, CSRF qorunması, parol heşləmə, giriş doğrulaması və SQL inyeksiyasının qarşısının alınması
Verilənlər bazası, e-poçt, sessiyalar, formalar, fayl yükləmələri, səhifələmə və s. üçün zəngin kitabxana dəsti
Praktiki nümunələrlə aydın, hərtərəfli istifadəçi bələdçisi və aktiv icma dəstəyi
sudo apt update
sudo apt install php8.1 php8.1-{fpm,cli,mysql,mbstring,xml,curl,intl,zip,gd} -y2. Composer quraşdırın:curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer3. CodeIgniter-i Composer vasitəsilə quraşdırın:cd /var/www
composer create-project codeigniter4/appstarter myproject
cd myproject4. İcazələri təyin edin:sudo chown -R www-data:www-data /var/www/myproject
sudo chmod -R 755 /var/www/myproject
sudo chmod -R 777 /var/www/myproject/writable5. Mühiti konfiqurasiya edin:cp env .env
nano .envKonfiqurasiyanı təyin edin:CI_ENVIRONMENT = development
database.default.hostname = localhost
database.default.database = mydb
database.default.username = dbuser
database.default.password = dbpass
database.default.DBDriver = MySQLi6. Apache virtual hostunu konfiqurasiya edin:sudo nano /etc/apache2/sites-available/myproject.confƏlavə edin:<VirtualHost *:80>
ServerName myproject.local
DocumentRoot /var/www/myproject/public
<Directory /var/www/myproject/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/myproject_error.log
CustomLog ${APACHE_LOG_DIR}/myproject_access.log combined
</VirtualHost>Saytı aktivləşdirin:sudo a2ensite myproject.conf
sudo a2enmod rewrite
sudo systemctl restart apache27. Və ya Nginx-i konfiqurasiya edin:sudo nano /etc/nginx/sites-available/myprojectƏlavə edin:server {
listen 80;
server_name myproject.local;
root /var/www/myproject/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}Aktivləşdirin:sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx8. MySQL-i quraşdırın və verilənlər bazası yaradın:sudo apt install mysql-server -y
sudo mysql
CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'dbpass';
GRANT ALL PRIVILEGES ON mydb.* TO 'dbuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;9. Miqrasiyaları işə salın (istifadə olunursa):php spark migrate10. Quraşdırmanı yoxlayın:php spark serve
# Visit http://localhost:8080
# Environment
CI_ENVIRONMENT = production # development, testing, production
# Base URL
app.baseURL = 'https://yourdomain.com/'
# Database
database.default.hostname = localhost
database.default.database = mydb
database.default.username = dbuser
database.default.password = secure_password
database.default.DBDriver = MySQLi
database.default.DBPrefix =
# Encryption
encryption.key = your-encryption-key-here # Generate: php spark key:generate2. Marşrutların konfiqurasiyası (app/Config/Routes.php):<?php
$routes->get('/', 'Home::index');
$routes->get('blog', 'Blog::index');
$routes->get('blog/(:segment)', 'Blog::view/$1');
// RESTful API routes
$routes->resource('api/users');
// Group routes
$routes->group('admin', ['filter' => 'auth'], function($routes) {
$routes->get('dashboard', 'Admin\Dashboard::index');
$routes->resource('posts');
});3. Verilənlər bazasının konfiqurasiyası (app/Config/Database.php):<?php
public $default = [
'DSN' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'mydb',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => true,
'charset' => 'utf8mb4',
'DBCollat' => 'utf8mb4_general_ci',
];4. Controller nümunəsi:<?php
namespace App\Controllers;
class Blog extends BaseController
{
protected $blogModel;
public function __construct()
{
$this->blogModel = model('BlogModel');
}
public function index()
{
$data = [
'posts' => $this->blogModel->paginate(10),
'pager' => $this->blogModel->pager
];
return view('blog/index', $data);
}
public function view($slug)
{
$post = $this->blogModel->where('slug', $slug)->first();
if (!$post) {
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
}
return view('blog/view', ['post' => $post]);
}
}5. Doğrulama ilə Model nümunəsi:<?php
namespace App\Models;
use CodeIgniter\Model;
class BlogModel extends Model
{
protected $table = 'posts';
protected $primaryKey = 'id';
protected $allowedFields = ['title', 'slug', 'body', 'author_id'];
protected $useTimestamps = true;
protected $validationRules = [
'title' => 'required|min_length[3]|max_length[255]',
'slug' => 'required|is_unique[posts.slug]',
'body' => 'required'
];
protected $validationMessages = [
'title' => [
'required' => 'Title is required',
'min_length' => 'Title must be at least 3 characters'
]
];
}6. Forma doğrulaması:<?php
// In controller
public function create()
{
$validation = \Config\Services::validation();
$validation->setRules([
'email' => 'required|valid_email|is_unique[users.email]',
'password' => 'required|min_length[8]',
'confirm' => 'required|matches[password]'
]);
if (!$validation->withRequest($this->request)->run()) {
return view('register', ['validation' => $validation]);
}
// Save user
}7. Verilənlər bazası ilə iş (Query Builder):<?php
// Select
$users = $db->table('users')
->select('id, name, email')
->where('status', 'active')
->orderBy('name', 'ASC')
->get()
->getResultArray();
// Insert
$data = ['name' => 'John', 'email' => 'john@example.com'];
$db->table('users')->insert($data);
// Update
$db->table('users')
->where('id', 1)
->update(['status' => 'inactive']);
// Delete
$db->table('users')->where('id', 1)->delete();
// Join
$results = $db->table('posts')
->join('users', 'users.id = posts.author_id')
->get()
->getResult();8. Sessiyalar və autentifikasiya:<?php
// Start session
$session = session();
// Set session data
$session->set('user_id', 123);
$session->set('logged_in', true);
// Get session data
$userId = $session->get('user_id');
// Flash data (available only on next request)
$session->setFlashdata('success', 'Login successful!');
// Destroy session
$session->destroy();9. Keşləmə:<?php
$cache = \Config\Services::cache();
// Save to cache
$cache->save('user_123', $userData, 3600); // 1 hour
// Get from cache
$data = $cache->get('user_123');
// Delete from cache
$cache->delete('user_123');
// Clear all cache
$cache->clean();10. CLI əmrləri (Spark):# Run migrations
php spark migrate
# Rollback migrations
php spark migrate:rollback
# Create migration
php spark make:migration CreateUsersTable
# Create controller
php spark make:controller Blog
# Create model
php spark make:model BlogModel
# Run seeder
php spark db:seed UserSeeder
# Clear cache
php spark cache:clearƏn yaxşı təcrübələr:Bizim sadə VPS işə salma prosesi ilə dəqiqələrdə başlayın
Deploy 2 dəqiqə ətrafında • tam root giriş • dəstək bilet və e-poçt