rcarvello / webmvcframework

PHP MVC framework for bulding web applications
http://www.webmvcframework.com
Other
53 stars 16 forks source link

Feauture request: Define a generic prefix possibility of any table at the MVC framework level; Show a debug error, if table does not exists #4

Closed DeRaja closed 6 years ago

DeRaja commented 6 years ago

Hello Rosario,

This request is not a bug but an idea of enhancement in the framework, not urgent or necessary at all. I just thought that this might help others. If you think this is not something others could use it, then please close this request.

In my case I added a prefix to all tables in DB and scripts. Then I created a prefix_new_table to generate a drop down in the Views and save it in prefix_user. The prefix_new_tableID from the prefix_new_table is added in the prefix_user table.

When I use {$this->userTable} instead of prefix_user table in the SQL Query, for example in framework/User.php ---> public function login, it shows a blank page. This gave me an idea to suggest:

1) Develop a generic method to use a prefix for a table as global variable. 2) Show a debug error if the prefix_table does not exists instead of a blank page.

This error cropped up while developing. I was about to change the use models\beans\BeanUser; ---> use models\beans\BeanPrefixUser; in all scripts everywhere. At this time, this error showed up. Here, it struck me that a debug error could be helpful. Otherwise, everything in the default MVC of User_Account is working fine, showing of data, updating, etc and the Controller, Models, Views and html is properly configured.

So keeping all the working parameters the same, this error got fired in this special circumstance and did not show up any debug info.

rcarvello commented 6 years ago

The text below is extracted from framework wiki. I hope it can be useful

Introduction

Object-relational mapping (ORM) is a mechanism that makes it possible to address, access and manipulate objects without having to consider how those objects relate to their database tables.
WebMVC provides you with a useful tool for the Object Relation Mapping of MySQL. The tool generates automatically Model classes for any tables of a given database schema.

WebMVC Model and ORM - Object Relational Mapping

To generate Model classes with the purpose of mapping database tables you need to:

1) Use lowercase with the underscore, which is the widely used MySQL naming notation, on your database tables and fields names. Important !!! Many of the features and automation of the framework are due to the use of specific naming conventions for classes, subsystems and even database tables.

2) Configure your database schema by modifying util\mysqlreflection\mysqlreflection.config.php file and, assigning appropriate values to DBHOST, DBNAME, DBUSER, DBPASSWORD, and DBPORT PHP constants, according to your MySQL settings.

3) Then, launch the tool by typing:
http/localhost/util/app_create_beans.php Note that, the GUI of the utility uses Bootstrap and jQuery from CDN. So you also need an internet connection alive before running it.

3) Once the utility is started, click "Generate classes" button.

The following figure shows you the startup screen of the utility:

Utility GUI

alt tag

After running the generation of classes you can close the utility. You will find all the generated classes under models\beans folder.

Notice that:

Each auto-generated Model, widely known as a Database Bean, provides you with the following:

Notice that ORM doesn't relieve you from a good DB design. This means you must design a good relational database schema, before using the ORM engine provided by WebMVC.

DeRaja commented 6 years ago

Hello Rosario,

Thanks for taking your time in informing me.

I am not only impressed by your work but also by your active support.

Actually I came here to enhance my error reporting and close the thread. You were faster. The error above showing white pages was due to tables, when I had not yet generated Beans and was trying to add a new field in the users table. After generating it and modifying scripts, I was able to work with the Framework in a fully functional way.

Thereafter, I worked further by continuously generating Beans. But white pages show up many times and the MVC Framework did not take care of any debug info. Thats what is missing, which is the second aspect of my message above. Now, when such an error is thrown, I will observe it carefully and collect its information and open a new thread on that specific error. I will report it in details then.

Here is the Link: https://github.com/rcarvello/webmvcframework/wiki