Search code examples
phpsecurityscaffolding

Function that creates a Model View and Controller. (how to call safely)


Sorry for the confusing title, however,

I'm interested in creating a function that creates new default model, view, and controller files with the name i supply through the function to a defined URL directory.

To be more clear, i want to auto create a model view and controller through one function and place them in my directory without having to individually create and label them.

The process seems quite clear, though my concern is finding the best way to call this function only when i need it and assuring that random users cant access it and create a bunch of files on my server. Would this be something i create in a form on a restricted page?

To be more clear in my question:

What would be the best and most secure way to call this function?


Solution

  • More secure is to use CLI - Command Line Interface, For example Laravel's Artisan CLI:

    php artisan:makemigration create_table
    

    Creates Migration files in app/database/migrations folder, or:

    php artisan controller:make PhotoController
    

    Creates controller in app/controllers folder So it's not secure if this function will be in WEB PAGE, because anyone can access it and manipulate your project, more secure in CLI, when you connect your server by SSH connection and type some commands. Hope I help.