Ok, I understand. People that would look at my code are doing me a favor. So ask them to also download the code maybe is too much.
So I will do my best to explain what this is about and put some code sample.
Preface: Someone asked me to make a test. He was looking for a real php-expert. I have many years experience in PHP. And
I think I am good enough.
The test was about doing a simple PHP-application, with js/css/html, for managing employers.
When I sent the zip package with the code, after he reviewed it, he said that its not enough. He needs someone very
experienced. Yes, Im very angry, even because he didnt tell me what part of the code makes him understand/think Im not
enough experienced. Yes, I need to learn more, like everybody. But it would be a good idea to know what part
of the code is not considered qualitative.
I tried to make something similar to Codeigniter. The head folder contains the subfodlers:
app, database, logs, www
In app there are the folders models and views. And also the folder config, containing environment.php and bootstrap.php.
In app/models there are the classes: Admin.php (to handle admin login, the admin needs to manage employees),
Database.php (which basically has the method connect and the mysql->close in the destructor.), the class Employee itself,
with all the crud methods, and Logger which contains the static method for writing to log folder.
In app/views there are the index.php for showing html for the login. The home.php for listing the employees.
Then there is employee_form which is used both for creating and editing an employee. Depending on the params
sent to this view, it will customize messages for whether its about editing or creating.
The last view is layout. In the middle it includes the view file itself (index, home or employee_form).
The head folder "database" only contains the schema for the DB. Im using indexes for all the fields that can be
in where or order by.
In www there are index (which includes the view index), home (which includes the view home), newemploye and editemploye.
Yes, there is no controller folder. There is the risk for repeating code. But I was not really sure about having an htaccess to redirect
every request to a single index, which in turn should select the controller. But I think its quite ok. Then a page like www/home.php
looks something like this:
<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/config/config.php');
require_once(APP_PATH . '/config/bootstrap.php');
$employee = new Employee($db);
$all_employees = $employee->get_all();
$view_name = 'home';
require_once(APP_PATH . '/views/layout.php');
In bootstrap the db-instance is created. COnnection to it is made. And reference to db is passssed to the Employee-class
(so it can use mysql).
Im using things that are considered important to make good and secure code.
Im omitting the closing php-tag.
Im escaping all the strings with real_escape_string(Im using mysqli).
Im printing all the GET/POST and data from DB using htmlspecialchars.
Im logging errors to the customized Logger class.
Im using an home made FlashMessages for printing messages on the page.
Guys, I hope you read until here. Im aware that you never end learning new things. But I have alot of experience.
This guy says Im not experienced enough. I want to know why. I want to improve my coding skills.
What do you think?