Questions PHP js script path, picture path, style path related issues

Source: Internet
Author: User
Questions PHP js script path, picture path, style path problem!
According to the truth of this kind of common problems to find the answer, but the more I see the more confused. Let's see if my understanding is correct.

I wrote a single entry program by myself. This means that all the module's action is to go root/index.php. The model name and the action name and the method name and the parameter name are added later.

Index.php?model=user&action=login&method=check
App:init (); require_once:app.class.php

Inside the app, you get the model and action and then dynamically execute the action class as follows:
UserLoginAction.class.php

Public function Check () {
If successful then jump
The problem: Jump I use here is require_once admin_index.php, because some variables I want to use in admin_index.php, so no redirect, I do not have a better way ah. This is not like Java, which can pass objects to a JSP. You can use $_session[' Uservo '], but I'm not used to passing a thing with the SESSION, so just include it directly. But that's the problem.
}

Admin_index.php inside the picture, CSS file, js file path How to deal with AH?
I have no way now, all with absolute path directly to write dead.

admin_index.php
If using relative path: $currentfolder = DirName (__file__); It's not a good idea, is it? You think, all the picture files are preceded by a
/images/logo.jpg "/>

I can understand require and include, which is equivalent to copying the code that introduces the file into the current index.php file. So the path that was introduced into the file is actually the directory where the index.php is located. If all the absolute path is not good AH (this is my last trick)


The DirName (__file__) method also has a problem: this is returned as if it were a physical path to the file. It's not something that everyone knows?

Last trick: all with physical path./Indicates the current path is relative to the root directory index.php: Anyway, the program starts and ends up in a file. All paths are written dead with./start.

////////////////////////////////////////////////////
Who's got a better idea? Thank you so much.

------Solution--------------------
If you don't mind, you can use $_server[' document_root ') This will be stronger than your absolute path.

Actually there are many ways. I still use relative. Of course, sometimes the path of insanity, then modify the way of the include, less to create their own cases.
------Solution--------------------
If it is a self-written frame, there are two ways to handle it:

One is to set global variables or functions such as define (' Style_path ', ' xxxx '); This recommendation, if you change the server, a change can be diverted.

The second is to use Base_url (); Gets the path of the relative root directory of your index.php file. (This is required for all internal URLs, as opposed to inside the program)

This way, no matter where you go, the program is not wrong.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.