For doing CRUD using php, without using any frameworks, cakePHP, Smarty, what's the best way to organize php code into files? -


Assume that I have a database table "widget"

What should be an index.php different Large switch statements for tasks such as "list_widgets", "edit_widget", "new_widget", "delete_widget" ... and then for all those functions in a separate file?

Or, there should be list_widgets .php, edit_widget.php, delete_widget.php ....

Or is there some other way?

Edit (after reading the first answer) I'm really asking, what are the names of files on my hard drive. If I am ready to create a website that only has the same host of widgets What will be the names of the files on my hard drive for that project?

(My motive for avoiding the framework is that this project is a learning exercise for Php and mysql, so I do not want anything happening automatically)

< / Div>

If this is a learning practice with PHP, then what are your goals? Do you want to implement full MVC architecture (just for exercise)? Do you want to use a front controller who requests specific controllers? Or do you want to create a simple script site that is able to edit your table widget only?

If it is any earlier, I would recommend that you apply the document and source code to a framework (I specifically like the Zend Framework) and then apply the version of your own MVC and / or Front controller Additionally, you can read where Rasmus talks about creating a simple MVC application without using an existing framework.

If you want to complete the latter (edit your table of widgets), then I would recommend that you keep things simple so I want to:

  • function Create files with (widgettables.fp), which interact directly with the table. For example, insert (), update (), delete (), fetch (), news ()
  • Create a file (index.fp or widget .php) that you will interact directly (some paragraphs This page will be the controller in this file) This file will include functions such as action (), list action (), action (), showformaction (). This will be the page in which calls are made and will interact with functions functions (or class methods) on this page that you created in the first file.
  • Create a folder called Visual or Template and create a corresponding view or template file for each action in Widgets.php For example you can create list.php, showForm.php, create.php.

This will ensure that you have a proper separation of concerns and it will make it easier to adjust the overall project structure later if you think you need it

Best wishes with your learning project! : -)


Comments