Command-Line (CLI)

PHPFast includes a built-in command-line interface (CLI) that significantly enhances development efficiency by automating essential tasks such as creating Controllers, Models, and synchronizing database structures. This CLI tool eliminates much of the manual effort involved in setting up application components, allowing developers to streamline their workflow and maintain better project organization.

By leveraging the PHPFast CLI, developers can quickly generate the fundamental building blocks of an application using simple commands. Instead of manually writing boilerplate code, the CLI automates the process, ensuring consistency and reducing development time. This is particularly useful for database-driven applications, as it simplifies model management and table synchronization.

Database Synchronization

One of the core capabilities of the CLI is the ability to synchronize the database with the application’s models. The tool reads the schema defined in a model’s _schema() method and automatically applies any necessary changes to the database structure. This ensures that the database tables remain up-to-date without requiring manual SQL modifications.

Command Usage:

php init table <table_name>

Example:

php init table users

This command ensures that the users table aligns with the corresponding model’s schema, making schema updates seamless and efficient.

Creating Controllers

The CLI allows developers to quickly generate new controller files, which serve as the backbone of application logic. When a new controller is created, it follows a predefined structure, enabling faster setup of routes and business logic. This approach enforces consistency and reduces redundant coding efforts.

Command Usage:

php init controllers <controller_name>

Example:

php init controllers Users

This creates a UsersController.php file inside the application/Controllers/ directory, ready for further customization.

Creating Models

Models play a crucial role in defining database structures and handling data interactions. The PHP-Fast CLI simplifies model creation by generating files that include a default schema definition and built-in CRUD (Create, Read, Update, Delete) functionalities. This enables developers to establish and manage database connections effortlessly.

Command Usage:

php init models <model_name>

Example:

php init models Users

This creates UsersModel.php inside the application/Models/ directory, complete with a predefined schema for handling database operations efficiently.

Why Use PHPFast CLI?

  • Speeds Up Development: Automates repetitive tasks like creating models, controllers, and syncing tables.

  • Ensures Consistency: Standardizes file structures and database schemas across the application.

  • Reduces Errors: Minimizes the risk of human error in database schema management and code structuring.

  • Enhances Maintainability: Provides a structured and scalable approach to application development.

By integrating these CLI functionalities, PHPFast optimizes the development process, allowing teams to focus on business logic and feature implementation rather than repetitive setup tasks. Whether working on a small project or a large-scale application, the PHPFast CLI is a powerful tool that enhances efficiency and streamlines development workflows.

How to create a new Command?

Last updated

Was this helpful?