[Question] PHPjs script path, image path, and style path

Source: Internet
Author: User
[Question] PHPjs script path, image path, and style path problems! According to the principle, you can find answers to these common questions, but the more you see, the more confused you are. Check whether my understanding is correct. I wrote a single-entry program myself. That is to say, the actions of all modules are based on root/index. php. Add the model name and action name and method name and parameter name. [Question] PHP js script path, image path, and style path!
According to the principle, you can find answers to these common questions, but the more you see, the more confused you are. Check whether my understanding is correct.

I wrote a single-entry program myself. That is to say, the actions of all modules are based on root/index. php. Add the model name and action name and method name and parameter name.

Index. php? Model = user & action = Login & method = check
App: init (); // require_once: app. class. php

In the app, you can obtain the model and action and dynamically execute the Action class as follows:
UserLoginAction. class. php

Public function check (){
// Jump if successful
The problem is: I used require_once admin_index.php to jump to the page. because some variables I want to use in admin_index.php, there is no redirection, and I have no better solution. Unlike JAVA, the object can be passed to JSP. You can use $ _ SESSION ['uservo '], but I am not used to passing a thing using Session, so I simply include it directly. But the problem arises.
}

What are the paths of images, CSS files, and JS files in admin_index.php?
I can't do it now. I can't write it all in absolute paths.

Admin_index.php
If the relative path is $ currentfolder = dirname (_ FILE _), isn't it a solution? Think about it. add
/Images/logo.jpg "/>

I can understand the methods of require and include, which is equivalent to copying the code of the introduced file to the current index. php file. Therefore, the path in the introduced file is actually the directory where index. php is located. It would not be good if all of them use absolute paths (this is my last move)


There is another problem with the dirname (_ FILE _) method: This returns the physical path of the FILE. This is not all for others to know?

Last trick: use the physical path./to indicate the current path relative to the root directory index. php: The program is executed in a file from the beginning to the end. All paths start.

//////////////////////////////////////// ////////////
Who has a better solution? Thank you very much.

------ Solution --------------------
If you don't mind, you can use $ _ SERVER ['document _ root'], which is better than using an absolute path.

There are actually many methods. I still use the opposite method myself. of course, sometimes it will make mental disorder to the path, so I will modify the include method to make fewer cases for myself.
------ Solution --------------------
For self-written frameworks, there are two ways to handle them:

One is to set global variables or functions such as define ('style _ path', 'xxxx'). We recommend that you change the server to a different one.

The second is to use base_url (); to obtain the path of your index. php file relative to the root directory. (This is only relative to the internal program. In fact, all internal URLs must be constructed)

In this way, no matter where your portal is, the program will not be 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.