How can I keep my pages organized?

Asked

Viewed 50 times

0

I am developing a system, in some files I came across a lot of codes in JS inside my files of PHP and a large amount of modals bootstrap also.

But what’s the problem?

I know that the correct thing is to keep the files of each language separate from each other, but I believe on account of organization. And I started to feel uncomfortable with it, and I decided to try to organize in a better way.

At the end of my HTML page, I used these 2 codes:

<!-- Incluindo modals utilizados nessa página -->
<?php include('organizacao_paginas/Modals/painel-admin.php') ?>

<!-- Incluindo scripts e funções utilizadas nessa página -->
<script src="organizacao_paginas/JS/painel-admin.js"></script>

Apparently the first include, is working normally, I can open the modals and etc.

But the <script src=...> no longer is, all functions of this page, do not work, I have tried to put the same inside the <head></head> and also use its own include, but without success.

How can I be including this file JS so that it works normally?

I’m sorry if I said something incoherent, you can correct me and thank you all from now on.

  • It’s probably a problem as your relative path src.

  • Ever tried to put a . / before the path in the script?

  • Already yes, without success.

  • Can send print with folder/file structure?

  • @user210741 you would need to show the directory structure that this file(s) (s) is. Do they run from any subfolder? If yes, it may be the problem, but it gets hard to do without knowing more details.

  • @Luizfelipe tried to use the 3, but without success...

  • @Wallacemaxters I’m surprised, because the 2 files I’m trying to include, is in the same folder, and only 1 is working. View the folders

  • An interesting solution is also to use an architecture standard to keep the code cleaner, you can opt for example for MVC, is a great solution!

  • I’ll do a search, thanks! @user210680

Show 5 more comments

1 answer

0


I solved my problem that way: I pressed (CTRL + U), and went down to see if the page was being included or not, and realized that it was not.

For some reason with <script src=""...> did not work, but worked using include in that way:

<script>
<?php include('organizacao_paginas/js/painel-admin.js'); ?>
</script>
  • Yes, but in this case you have to note that you are not using the script as a resource external, but from the page itself. Depending on the case, it may not make a difference, but it has to be known that they are different things. Another way to see this is that you are now delegating to PHP the responsibility of "importing" something that used to be the role of browser (<script src="..."></script>).

  • Yes, I only used to be more organized "in my view", but I know that internally the code is there rsrs, I would really like to use the <script src="..."></script>, however, it was not working :(

Browser other questions tagged

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