Models Command

This ModelsCommand class is a CLI command used to generate new Model files dynamically in the PHPFast framework.

public function create($modelName) {
        // Define the path for the new model
        $modelName = ucfirst($modelName);
        $modelPath = ROOT_PATH . '/application/Models/' . ucfirst($modelName) . 'Model.php';
        
        // Check if the model already exists
        if (file_exists($modelPath)) {
            echo "Model {$modelName} already exists.\n";
            return;
        }

        // Define the contents of the model
        $modelContent = // Model File Structure

        // Create the model file
        file_put_contents($modelPath, $modelContent);

        echo "Model {$modelName}Model has been created successfully.\n";
    }

If you want to create a new Model and named as 'User', run the following command:

If UserModel.php is exist:

If UserModel.php is not exist, it will be generated:

Last updated

Was this helpful?