Link through class or method css file in php

0

I have been developing a project with php, but I am currently in a problem that is my php files of views have linked many css and js files, but as I am calling them from a router those relative paths are lost, I know that a solution It would be to place an absolute route, but it is not what I would like to see better the structure of my project.

Is there any way to create a method or a class that can make those css and js links to php views?

  

I'm organizing everything to mvc

I have a lot of css, js, img and fonts which I want to link, is there any libreria or something similar to be able to establish some order or how could I do that? I am currently running it on a local nginx server

.
├── app
│   ├── controllers
│   └── models
├── composer.json
├── composer.lock
├── public
│   ├── img
│   │   ├── awards-img
│   │   │   ├── a-1.png
│   │   │   ├── a-2.png
│   │   │   ├── a-3.png
│   │   │   ├── a-4.png
│   │   │   └── a-5.png
│   │   ├── bg-img
│   │   │   ├── about-1.jpg
│   │   │   ├── about-2.jpg
│   │   │   ├── hero-1.jpg
│   │   │   ├── hero-2.jpg
│   │   │   ├── hero-3.jpg
│   │   │   ├── hero-4.jpg
│   │   │   └── hero-5.jpg
│   │   ├── core-img
│   │   │   ├── about-dots.png
│   │   │   ├── point.png
│   │   │   ├── preload-1.png
│   │   │   ├── preload-2.png
│   │   │   ├── preload-3.png
│   │   │   └── special-dots.png
│   │   ├── icons
│   │   │   ├── cancel.svg
│   │   │   ├── email.svg
│   │   │   ├── left-arrow.svg
│   │   │   ├── phone.svg
│   │   │   ├── point.svg
│   │   │   ├── quotation-mark.svg
│   │   │   ├── right-arrow.svg
│   │   │   └── search.svg
│   │   ├── menu-img
│   │   │   ├── dish-1.png
│   │   │   ├── dish-2.png
│   │   │   └── dish-3.png
│   │   └── testimonial-img
│   │       ├── 1.jpg
│   │       ├── 2.jpg
│   │       └── 3.jpg
│   └── index.php
├── regular-page.html
├── resources
│   ├── assets
│   │   ├── css
│   │   │   ├── bootstrap
│   │   │   │   └── bootstrap.min.css
│   │   │   ├── others
│   │   │   │   ├── animate.css
│   │   │   │   ├── font-awesome.min.css
│   │   │   │   ├── magnific-popup.css
│   │   │   │   ├── owl.carousel.min.css
│   │   │   │   └── pe-icon-7-stroke.css
│   │   │   └── responsive
│   │   │       └── responsive.css
│   │   ├── fonts
│   │   │   ├── FontAwesome.otf
│   │   │   ├── fontawesome-webfont.eot
│   │   │   ├── fontawesome-webfont.svg
│   │   │   ├── fontawesome-webfont.ttf
│   │   │   ├── fontawesome-webfont.woff
│   │   │   ├── fontawesome-webfont.woff2
│   │   │   ├── Pe-icon-7-stroke.eot
│   │   │   ├── Pe-icon-7-stroke.svg
│   │   │   ├── Pe-icon-7-stroke.ttf
│   │   │   └── Pe-icon-7-stroke.woff
│   │   ├── js
│   │   │   ├── active.js
│   │   │   ├── bootstrap
│   │   │   │   ├── bootstrap.min.js
│   │   │   │   └── popper.min.js
│   │   │   ├── google-map
│   │   │   │   └── map-active.js
│   │   │   ├── jquery
│   │   │   │   └── jquery-2.2.4.min.js
│   │   │   └── others
│   │   │       └── plugins.js
│   │   └── style.css
│   └── views
│       ├── contact.php
│       ├── index.php
│       ├── layouts
│       └── menu.php
└── vendor
    
asked by Asdrubal Hernandez 12.08.2018 в 04:39
source

1 answer

1

You can do the following, I do not know if it is exactly what you are looking for, I show you an example that you use:
js.php

<!-- ESTE ARCHIVO CONTIENE LOS JS GLOBALES.
AL LLAMAR A ESTE ARCHIVO DESDE EL CONTROLADOR SE CARGAN LOS JS. -->
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<script src="<?php echo base_url('js/jquery-3.3.1.min.js');?>"></script>
<script src="<?php echo base_url('js/w3codecolor.js');?>"></script>
<script src="<?php echo base_url('js/images.js');?>"></script>
<script src="<?php echo base_url('js/dates.js');?>"></script>
</head>

archivo.php

<?php
    require_once('js.php');
?>

I do not know if it is the most recommended practice, but it can be done in that way. What is lost is selectivity, that is, all your files that perform the require_once will load all the js or css whether they use it or not.

    
answered by 12.08.2018 в 16:48