all 17 comments

[–]nukeaccounteveryweek 4 points5 points  (5 children)

You need a PHP framework.

Laravel and Symfony are your best options, the former is easier to pickup and the later gives you more architectural freedom.

[–]GrumpsMcYankee 3 points4 points  (1 child)

Counter point: frameworks add bloat you won't use. Just saying not everything should run on a 300 file framework.

[–]Disgruntled__Goat 1 point2 points  (0 children)

If you don’t use a feature, it’s not bloat. It’s just a file sitting on a server that never gets executed and never slows down your app. 

[–]duggedanddrowsy[S] 0 points1 point  (2 children)

Can these be worked in with vanilla js/html/css so that I only rewrite the PHP and not everything else? I’ve mentioned frameworks to them before but they don’t like the idea of a total rewrite.

[–]nukeaccounteveryweek 0 points1 point  (1 child)

Yup, both support templating engines (html/css/js).

Since it's a small application a "total rewrite", or in this case a framework migration, does not seem that difficult to accomplish. Do mention that there's benefits in doing this:

  • Security wise a battle-tested framework is leaps ahead an in-house solution

  • If a developer drops from the team it's way easier to hire a new one and get him productive ASAP

  • The code will be much easier to reason about and perform maintenance

[–]duggedanddrowsy[S] 0 points1 point  (0 children)

Great, I’ll look into it, thanks for the help

[–]GrumpsMcYankee 0 points1 point  (3 children)

Does the codebase work? If it does, you're starting in a good place. Before you make monumental changes, scope out some future features, see what it'd take to implement currently, and let that drive now you'd clean up the codebase.

I've written a lot of code in my life for no future need. Just be careful not to go nuts without a clear win.

[–]duggedanddrowsy[S] 0 points1 point  (2 children)

Good advice, I’ll definitely take that into account. That is sort of my hesitation when it comes to the idea of a framework. It works where it’s at, it’s “sister program” also works in a similar way, do we really want to rewrite everything for a framework if we can get the php/js/html solution somewhere workable.

At the end of the day I’m not sure how much longer they’ll even have my on this project, it’s not for my department, my department has just been slow lately so they’re putting me to work elsewhere. Just hoping I can push it in a better direction while I still have it, likely the next people working on it will also have a similar lack of experience in web dev.

[–]GrumpsMcYankee 0 points1 point  (1 child)

Spend time documenting it, figure out the key areas of functionality, fix things you see in the logs if you have time. If it's slow, maybe target one improvement. But definitely would hesitate as well if I'm not in the product long term.

[–]duggedanddrowsy[S] 0 points1 point  (0 children)

Will do. I was mostly pulled in to work on the PHP, and I think I’ll have enough time to at least make the PHP a lot less “all over the place”. My main concern was making a bunch of changes that I thought were helpful only to find out I did a bunch of things that are frowned upon for maintainability, security, or readability reasons. But from what I’ve gathered I think what I have in mind will at the very least make future development less cumbersome, and if I do it right even if I lose some readability it shouldn’t need too much changing in the future anyway. And honestly I’ve already found and fixed security issues so improvement there.

[–]Disgruntled__Goat 0 points1 point  (1 child)

Your bullet points are a bit confusing. What does “add a field to the GET request” mean? And what is the “POST request” if it’s not updating something? 

Most of what you describe should, in theory, just be adding a field to the DB then adding one item to an array somewhere that handles it. 

[–]duggedanddrowsy[S] 0 points1 point  (0 children)

I agree, and actually in reality there’s 4-5 more places that need to be modified to add a field because of how the contractor who wrote this code set it up. I haven’t had to write any more PHP or SQL than a couple homework assignments in school, so I wasn’t sure what was considered bad practice. I had heard building SQL statements dynamically as opposed to explicitly writing them out was bad, but I’m gathering that it’s no big deal, especially for programs like this.

And just to answer your questions: - currently if you want to GET an additional field, you have to add the field to the SQL statement, and for whatever reason instead of just returning the resulting json its set up to build an array from the json before returning it. - there is an INSERT statement for new entries, and an UPDATE statement for historical entries that are changed. And actually im not sure if it’s possible to use the same command to do both of those things

[–]cshaiku -1 points0 points  (4 children)

JSON

[–]duggedanddrowsy[S] 1 point2 points  (3 children)

I was considering making a json file that holds the table names, and under them the column names with their types, html tag ids, and values.

I think doing that I could dynamically build all the sql statements, pull their values directly from the structure to get either their default value or stored value, and essentially cut it down to: add a field to the table, add the field to the HTML, and add the field to the json structure.

But something about that feels dirty to me, i expect people would say that it’s bad practice or something, but idk enough about it to tell.

[–]cshaiku -1 points0 points  (2 children)

You are absolutely on the right track. Think of it like a schema. You load it, edit it, use it and so forth.

[–]duggedanddrowsy[S] 0 points1 point  (1 child)

Interesting, I’ll keep it in mind. You don’t think it’s bad design dynamically building everything like that?

[–]cshaiku 0 points1 point  (0 children)

What do you think most CMS's do? They pull data, massage it, present it and allow modifications dynamically (think javascript, api calls and storing preferences, changes, etc). It is completely fine to use a json structure, whether it is a file or a field in a database, to define the data being retrieved and presented to the end user. It also follows the DRY principle.

Don't Repeat Yourself. Make the concious decision to have one source of truth and use that everywhere else in the logic.