WEB project organization standard (HTML, CSS, PHP)

Asked

Viewed 3,176 times

0

I don’t know exactly how to organize my project, I’m doing it this way:

/produtos/
  cabecalho.php
  index.php
  rodape.php

inside the header and footer has a

if(verificacao != 1){sai da pagina}

and my index defines the variable $verificacao = 1; so that pages can only be displayed from index.php

I know this is a scam, but it was a way that I found to organize my code and I’d like to know if there’s any design pattern, some documentation for it, some guidance, something like that.

Note: Create produtos.php and putting everything together is unviable because the code gets a huge mess (even having a separate file for CSS and JS).

  • 1

    Ok, what exactly is the problem you want to solve? Organizing folders or blocking some files from being accessed directly?

  • I would like a help on the organizing part.

  • 1

    The answer to this will be based on opinion, as provided in [help] (if you have not seen it, I recommend to access it and do the [tour]). There are no rules about how you will organize your project. Only you, as responsible, can determine based on what makes your life easier.

  • Really I am the one who decides, however, I would like a help, from someone more experienced who has hit this key and found some light that helped kk.

  • Examples of organization, of your own projects or some of which you are based. My idea here is not to copy/imitate, but to analyze and create a "style" of their own from things that work and are really viable.

  • If you want a direction, look for HTML Boilerplate and study everything, but everything, from it.

Show 1 more comment

2 answers

8

First, there is no 100% sure way to standardize a project, what you have there are some pre-established standards by the community, which claims to be the best or the most accepted, until there appears some fault 'in this pattern' (whether security, usability, performance, etc.).

What I suggest, however, is to learn the fundamental points of the language itself that you have chosen to use as a working tool or by hobby same. Then learn some pattern of these already used, as for example the pattern MVC (Model-View-Controller), which, to me, is too complicated for a beginner to learn. Look at this: even Mozilla Firefox, on its development site, says that there is no standard. Facebook, through its React JS Framework, says the same thing.

If you take 100 projects from 100 different companies, you’ll see that, in a probability of almost 100 percent of them, the projects are different, and in some, they’re not in any of these pre-established standards.

Again, to conclude, Oboro saying that the most important thing is to learn the basics, that is, learn what your programming language does, its main features, etc., then, after you have at least a certain domain of it, choose a pattern of this. It could be up to MVC, but with the advent of functional programming, such as in React Js (front-end), it would be nice to learn both ways.

Also, see the difference between programming monolithic, which, in short, is to put everything in one place and programming based on services or in micro-services, that parts of your project are placed in different places. Currently, the latter is being widely accepted.

When you said: "the code gets a huge mess", you probably referred to the programming monolithic (even unknowingly), although in service-based programming, there is also mess.

The moment you really learn the basics of web programming, anything you put to learn, you’ll easily learn, even any pattern of this.

So, start with a basic structure (it can be monolithic), you can create it yourself; understand how you care about files, relative paths, absolute, for example: the difference include, include_once, require, require_once, etc., in php.

root:
    - index.php (caso seja php)
    - assets (onde irão os arquivos css, javascripts, fontes)
    - class (pode colocar algumas classes php)

I personally wouldn’t advise using such a standard (MVC, etc.) in the beginning, because you will not absorb much, and may even hinder learning in the beginning.

REFERENCE:

  1. https://en.wikipedia.org/wiki/Model–view–controller
  2. https://developer.mozilla.org/en-US/docs/Web/JavaScript
  3. https://pt-br.reactjs.org/docs/getting-started.html
  • I had already tried the MVC standard, but it is very complicated still kk, I knew that there was some other design pattern, but I did not know that it was called monolithic, you already gave me a very nice north, thank you very much for your reply, I will research on the content you indicated me.

1


Some like to impose a standard, the more you don’t need to follow them, the less you should believe in the phrase "don’t re-invent the wheel".

The advantage of following the standard is that you will know how to solve a problem faster and more practical, and can count on the help of other developers, without having to show your code, because you will be in accordance with the language documentation, framework or even CMS, then you can understand and use the examples that exist there (in the documentation), in addition, if you are doing a project for a client, follow the standard, it will make it easy for the next developer to modify the code, although some sabotage for the customer to return to who "resolves". You didn’t say whether you’re doing it in pure code or in a framework, more in pure php, you can do it like this:

/Assets 

   - css
   - img
   - js
   - vendor

/Int ou config

 - config.php
 - db.php
 - functions.php
 - route.php

// Aqui você coloca todos os arquivos de configuração

/Public

- index.php
- .htaccess
- manifest.json (opcional)
- sw.js (opcional)
- favicon.ico

/View
   - /layout
      - header
         - head.php
      - footer
         - footer.php
      - page.php // layout da pagina  

  - /page(s)
    // suas paginas aqui

Basically that is, however, it is easier to use the Lockable if you are running out of time, because, it already has everything there configured.

  • the names of the files do not accurately be in English, be wary of anyone who says that.

  • in the case of route.php, you can create a folder instead of a file, for example

    /router

    • api.php
    • php routes.
  • I prefer to replace /header and /footer by /global and put everything there, plus you decide who.

  • in the case of Public folder, when passing to the server, you can put the files in the project root, it is not necessary.

  • /Assets
  • /config
  • /router (optional)
  • /view
  • index php.
  • .htaccess
  • manifest.json (optional)
  • sw.js (optional)
  • favicon.ico
  • you can put all the pages in the view/pages folder, including the home, and use the index.php file, only to load libraries, as is done in the Standard.
  • 1

    Thank you so much for your reply, dear, that’s exactly what I wanted, a north so I could base myself and organize my project.

  • of nothing, needing to post again : )

Browser other questions tagged

You are not signed in. Login or sign up in order to post.