සංවර්ධන රාමු
වෙබ් යෙදුම් ගොඩනැගීම සඳහා කුඩා පියසටහනක් සහිත සැහැල්ලු PHP රාමුවක්.
කුඩා පාදමක් (2MB), අවම උපරි බර සහ අත්යවශ්ය සංරචක පමණක් පූරණය කළ විශිෂ්ට කාර්ය සාධනය
පෙරනිමි අගයන් සහිත ආසන්න වශයෙන් ශුන්ය-වින්යාස පිහිටුවීම - සංකීර්ණ වින්යාසයකින් තොරව වහාම කේතීකරණය ආරම්භ කරන්න
ඔබේ අවශ්යතාවලට අනුවර්තනය වීමේ නිදහස සහිතව MVC රටාව ලිහිල්ව අනුගමනය කරයි - සම්පූර්ණ MVC හෝ සරල කළ ප්රවේශය භාවිත කරන්න
XSS පෙරීම, CSRF ආරක්ෂාව, මුරපද හැෂ් කිරීම, ආදාන වලංගුකරණය සහ SQL injection වැළැක්වීම
දත්ත සමුදාය, ඊමේල්, sessions, forms, ගොනු උඩුගත කිරීම්, pagination සහ තවත් දේ සඳහා පොහොසත් libraries කට්ටලයක්
ප්රායෝගික උදාහරණ සහ සක්රීය ප්රජා සහාය සහිත පැහැදිලි, පුළුල් පරිශීලක මාර්ගෝපදේශයක්
sudo apt update
sudo apt install php8.1 php8.1-{fpm,cli,mysql,mbstring,xml,curl,intl,zip,gd} -y2. Composer ස්ථාපනය කරන්න:curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer3. Composer හරහා CodeIgniter ස්ථාපනය කරන්න:cd /var/www
composer create-project codeigniter4/appstarter myproject
cd myproject4. අවසර සකසන්න: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. පරිසරය වින්යාසගත කරන්න:cp env .env
nano .envසැකසුම් ලබා දෙන්න: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 Host වින්යාසගත කරන්න:sudo nano /etc/apache2/sites-available/myproject.confඑක් කරන්න:<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>අඩවිය සක්රීය කරන්න:sudo a2ensite myproject.conf
sudo a2enmod rewrite
sudo systemctl restart apache27. නැතහොත් Nginx වින්යාසගත කරන්න:sudo nano /etc/nginx/sites-available/myprojectඑක් කරන්න: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;
}
}සක්රිය කරන්න:sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx8. MySQL ස්ථාපනය කර දත්ත සමුදායක් සාදන්න: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. Migrations ධාවනය කරන්න (භාවිත කරන්නේ නම්):php spark migrate10. ස්ථාපනය පරීක්ෂා කරන්න: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. රවුම් වින්යාසය (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. දත්ත සමුදා වින්යාසය (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 උදාහරණය:<?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. වලංගුකරණය සහිත Model උදාහරණය:<?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. පෝරම වලංගු කිරීම:<?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. දත්ත සමුදාය සමඟ වැඩ කිරීම (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. Sessions සහ සත්යාපනය:<?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. හැඹිලි කිරීම:<?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 විධාන (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හොඳම පරිචයන්:අපගේ සරල VPS යෙදවීමේ ක්රියාවලිය සමඟ විනාඩි කිහිපයකින් ආරම්භ කරන්න
ගැන යෙදවීම2මිනිත්තු • සම්පූර්ණ මූල ප්රවේශය • ටිකට් සහ ඊ-තැපැල් මගින් සහාය