0

i have folders like this

\htdocs\router\index.php -> main index file
\htdocs\router\view\ -> all html and php files 
\htdocs\router\view\asset -> all css, js , etc files
\htdocs\router\controller\App\main.php -> controller file

Now when someone point to http://localhost, the index.php create new object (new main() ) from main.php (class main) and executes index function (public function index() { ... }) . This function have does an include like this ( require 'view/login.php'; ).

I can see the output of login.php but all .css, .jpg, .js files wont load because they are declared in login.php like this :

<link rel="stylesheed" href="asset/style.css" type="text/css">

because the asset/ directory is located where login.php file is.

if i put href="view/asset/style.css" it's working .

The question is :

How can i include a .php file from other folder to make it work without chaning the href tag and without moving the asset folder up.

6
  • Refer to your assets from the root, rather than using relative paths. You can't go wrong when you do it that way. Commented Apr 20, 2016 at 14:50
  • i know but the asset folder and login.php are both in view directory Commented Apr 20, 2016 at 14:51
  • If you can't/won't edit the login.php file there's nothing you can do. Well, there's things you could do but they're so convoluted they make very little sense to do. Commented Apr 20, 2016 at 14:53
  • Your index.php should be in the view folder, in that case. It's a view, is it not? All your view files should be in there. Commented Apr 20, 2016 at 14:54
  • How does your url look like when you visit login.php? Commented Apr 20, 2016 at 14:55

1 Answer 1

1

Actually, you can't make it work without changing href as assets refer to the root, not in the path.

What you can do is make a symlink of view/asset to root, So it will assets will be accessible from both href="asset/style.css" and href="view/asset/style.css".

Using PHP:

symlink("view/asset","asset"); //index.php

Or Terminal:

ln -s view/asset asset
Sign up to request clarification or add additional context in comments.

5 Comments

This is what i want to achieve. to just let asset/style.css in there and somehow make a link or something
use php build-in symlink() to create a symlink view/asset to root asset. symlink("view/asset","asset"); OR from command line ln -s view/asset asset
This is something what you want?
i am trying now .. sorry for delay
Glad it helps you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.