Kotchasan Framework Documentation
Kotchasan Framework Documentation
Kotchasan Framework Documentation
Kotchasan Framework is a powerful and flexible PHP framework designed for developing high-performance web applications. It supports multiple database systems including MySQL, PostgreSQL, MSSQL, and SQLite.
Framework Overview
Kotchasan Framework features:
- MVC Architecture - Clear architectural pattern
- Database Abstraction - Support for multiple database types
- Security First - Built-in security features
- Performance Optimized - Designed for high performance
- Developer Friendly - Easy to use and learn
Getting Started Guides
📚 Essential Guides
- Installation and Setup
- Database Usage Guide
- MVC Architecture Guide
- Basic Web Development Tutorial
- Example of actual use (recommend)
🏗️ Architecture and Patterns
- MVC Pattern - Model-View-Controller
- Database Layer - Database management
- Request/Response Handling - HTTP handling
- Routing System - URL routing
API Reference
🗄️ Database System
- Database - Main database class
- DB - Database Helper
- Model - Base Model Class
- QueryBuilder - Query Builder
🔗 Database Connections
- Connection - Database connection
- ConnectionManager - Connection management
- MySQL Driver
- PostgreSQL Driver
- MSSQL Driver
- SQLite Driver
🚀 Cache System
- Cache Overview - Cache system overview
- CacheFactory - Cache Factory
- FileCache - File-based Cache
- MemoryCache - Memory Cache
- RedisCache - Redis Cache
- QueryCache - Query Cache
🌐 HTTP and Web
- Controller - Base Controller
- ApiController - API Controller
- View - View management
- Request - HTTP Request
- Response - HTTP Response
- Router - URL Routing
🔐 Security and Authentication
- Login - Login system
- Password - Password management
- Session - Session management
- JWT - JSON Web Token
📝 Forms and Validation
🛠️ Tools and Utilities
- ArrayTool - Array manipulation tools
- Collection - Collection Class
- Text - Text processing
- Date - Date and time handling
- Number - Number processing
- File - File management
- Files - Multiple file management
- Image - Image processing
- Template - Template system
- Menu - Menu creation
- Tab - Tab Interface
- ListItem - List item handling
📧 Communication and Export
- Email - Email sending
- Pdf - PDF generation
- Csv - CSV handling
- Curl - HTTP Client
- Barcode - Barcode generation
🌍 Localization and Regional
- Language - Language management
- Country - Country data
- Province - Province data
- Currency - Currency handling
📋 Logging and Monitoring
- Logger Overview - Logging system overview
- Logger - Logger Class
Installation
System Requirements
- PHP 7.4 or higher
- Web Server (Apache, Nginx)
- Database (MySQL, PostgreSQL, MSSQL, or SQLite)
- Composer
Installation via Composer
Manual Installation (recommended)
- Download files from GitHub
- Extract files to your web directory
- Set write permissions for
datas/folder
composer create-project kotchasan/kotchasan myproject
cd myprojectInitial Configuration
// settings/database.php
return [
'default' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'mydatabase',
'username' => 'root',
'password' => 'password',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
]
];Basic Usage
Creating Database Instance
use Kotchasan\Database;
// Create database instance
$db = Database::create();
// Fetch data
$users = $db->select('*')
->from('users')
->where('status', '=', 'active')
->execute();Creating Controller
namespace MyApp\Home;
use Kotchasan\Http\Request;
class Controller extends \Kotchasan\Controller
{
public function render(Request $request)
{
$view = new View();
return $view->render();
}
}Creating Model
namespace MyApp\User;
use Kotchasan\Model;
class Model extends \Kotchasan\Model
{
protected $table = 'users';
public function getAllUsers()
{
return $this->db->select('*')
->from($this->table)
->where('status', '=', 'active')
->execute();
}
}Usage Examples
CRUD Operations
use Kotchasan\Database;
$db = Database::create();
// Create
$userId = $db->insert('users')
->values([
'name' => 'John Doe',
'email' => 'john@example.com'
])
->execute();
// Read
$user = $db->select('*')
->from('users')
->where('id', '=', $userId)
->first();
// Update
$db->update('users')
->set(['name' => 'Jane Doe'])
->where('id', '=', $userId)
->execute();
// Delete
$db->delete('users')
->where('id', '=', $userId)
->execute();Using Cache
use Kotchasan\Cache\FileCache;
$cache = new FileCache(['path' => ROOT_PATH . '/datas/cache/']);
// Store cache
$cache->set('user_list', $users, 3600);
// Retrieve cache
$cachedUsers = $cache->get('user_list');Transactions
$db->beginTransaction();
try {
$db->insert('users')->values(['name' => 'John'])->execute();
$db->update('accounts')->set(['balance' => 100])->execute();
$db->commit();
} catch (\Exception $e) {
$db->rollback();
throw $e;
}Error Handling
use Kotchasan\Exception\DatabaseException;
try {
$result = $db->select('*')->from('users')->execute();
} catch (DatabaseException $e) {
echo "Error: " . $e->getMessage();
echo "SQL: " . $e->getQuery();
}Additional Resources
Support
If you need help:
- Read this documentation and FAQ
- Search in the user community
- Create an Issue on GitHub
- Contact the development team
Note: This documentation is updated for the latest version of Kotchasan Framework. If you find errors or want to add information, please let us know.