Jump to content

Recommended Posts

Hi guys,

 

Hope you can help me! - I have been trying to learn php just from reading/trialing and error ect, also read that github is good for posting my projects so people can see ect.

 

So here it is: https://github.com/Joshinki/php-new

 

Could you let me know if I am on the right track with doing things? I know there is not much PHP in at the moment, but with placing of the classes ect

 

Thank you for your time.

 

Josh

Link to comment
https://forums.phpfreaks.com/topic/302362-am-i-on-the-right-track/
Share on other sites

First off: Kudos for creating this nice project as a beginner. It's rare to see such decent code and HTML markup on the first attempt. And it's even on GitHub! Give that man a medal.

 

There's nothing particulary wrong at this early stage. However, given your obvious talent and/or experience, I recommend you skip a few learning steps:

  • Right now, you're creating your dynamic HTML markup with PHP. That's possible, but it has several disadvantages: PHP is very verbose when used for this task, it forces you to put the HTML fragments together yourself (which can become very complex when you have arbitrarily nested components), it encourages you to mix application logic with visuals, and it's insecure in the sense that a “page” is a full-blown PHP application which can do anything from rendering HTML to formatting your HDD (when it should really just render HTML). Consider using a dedicated template engine like Twig or Smarty. It's much more compact, secure and takes care of many tedious template management tasks.
  • Rework your directory structure. All client-side resources (JavaScript files, CSS, images etc.) should be put into an extra folder like resources. The pages (or Twig templates) should be separated from the application core (which contains classes, libraries etc.) and again be put into an extra folder.
  • The index.php script should delegate the entire request to a special class which is associated with the URL and takes care of the processing. For example, a request to /index.php?page=invoice would be handled by an Invoice class, and the index script merely acts as a kind of router without generating any HTML markup on its own.
  • Like 1

Hello @Jacques1,

 

Thank you for your response, really appreciate you taking the time to view my project over!

 

1st Bullet - I didnt really understand - Are you suggesting that the way I am including PHP pages into another page is not the way to go?

2nd Bullet - Will take note of this, will change this now.

3rd Bullet - Would this index script pull the classes together then?

 

Thanks again!

1: My point is that you should stop generating dynamic HTML markup with PHP altogether. There are specialized languages like the already mentioned Twig which are much better for that (see the Twig homepage for a detailed comparison in terms of conciseness, security and ease of use). So PHP should only be used for the application logic and delegate all HTML-related tasks to a separate component. You'll immediately see that your core application becomes much simpler.

 

3: Yes. In professional applications, this is called a front controller: It receives all requests and then delegates the processing to individual objects for the various pages.

@Jacques1;

 

Slight off subject to my post, but since you had mentioned Front Controller ect, I have been reading more into MVC. I have checked some guides/tutorials on this and came up with:

 

https://github.com/Joshinki/php_mvc/

 

Took abit for me to get my head around it, Only question I have that I couldnt really find an answer on is a controller for every part of the site? (Login, Load News Article, Load Navigation) So you would have a seperate Controller on your homepage to view news ect, then another for loading a navigation?

There's a controller for every page, not for every GUI component. The purpose of a controller is to process a request to a particular URL.

 

GUI components are handled by the template engine (i. e. on the view layer).

Edited by Jacques1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.