php 路径 项目名
请问如何获取php 项目名 比如我的项目名是test 我如何获取到这个名字,
回复讨论(解决方案)
echo str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', dirname(__FILE__)));
echo str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', dirname(__FILE__)));
你好,因为公司有个项目是php的,刚刚接触php ,问题比较小白。
是这样的,我现在部署在本地 服务器项目路径D:/wamp/www/weimik, 我想得到weimik这个名字,因为在java中,这个是我所谓的项目名,因为之后我会把项目部署到linux上,我不知道到时取weimik 这个名字还和我截取weimik 这个方式一样不一样。
其实最终问题是,我想在一个php文件下引入不用目录下的php文件,我想在是这样引入的include("/weimik/Conf/Ip.php"); ,因为weimik可能会变所以我想 取项目名,谢谢
你的项目名指的是文件名($_SERVER['SCRIPT_NAME'])?还是目录名?(dirname(__FILE__))
你的项目名指的是文件名($_SERVER['SCRIPT_NAME'])?还是目录名?(dirname(__FILE__))
也就是有红线标记的名字,另外问一下如果引入不同目录的php 文件
你的项目有没有一个入口文件,在那个入口文件里定义你的项目名字,比如:define('APP_ROOT', '项目名');
用于包含文件涉及到文件系统路径,所以宜做到:被包含的文件在主文件的平级或下级目录中
这样用相对路径 include(‘./文件名'); 或 include(‘./目录名/文件名'); 就轻松实现了
如果因不合理的布局设计造成需要从下级目录包含上级目录(或上级目录的其他子目录)中的文件
可写作 include(__DIR__ . "目标文件相对当前目录的路径/文件名"); 来完成,显然计算相对路径是比较绕人的
你的项目有没有一个入口文件,在那个入口文件里定义你的项目名字,比如:define('APP_ROOT', '项目名');
有,但是我用的是define('APP_PATH','./weimicms/'); 用的是thinkphp 框架
你的项目有没有一个入口文件,在那个入口文件里定义你的项目名字,比如:define('APP_ROOT', '项目名');
有,但是我用的是define('APP_PATH','./weimicms/'); 用的是thinkphp 框架
用的是框架,那就好办了,TP里有个常量APP_NAME,在控制器里echo出来就是weimicms
你的项目有没有一个入口文件,在那个入口文件里定义你的项目名字,比如:define('APP_ROOT', '项目名');
有,但是我用的是define('APP_PATH','./weimicms/'); 用的是thinkphp 框架
用的是框架,那就好办了,TP里有个常量APP_NAME,在控制器里echo出来就是weimicms
再请教一个问题 ,现在我想用ajax post 请求到php 我看框架里面写的是index.php?g=User&m=Store&a=test 这种格式的路径,但是我写这个路径的时候去发现没有走test方法,我现在在微信开发,通过file_put_content方法发现没有写文件来判断有没有走test方法的
你的项目有没有一个入口文件,在那个入口文件里定义你的项目名字,比如:define('APP_ROOT', '项目名');
有,但是我用的是define('APP_PATH','./weimicms/'); 用的是thinkphp 框架
用的是框架,那就好办了,TP里有个常量APP_NAME,在控制器里echo出来就是weimicms
再请教一个问题 ,现在我想用ajax post 请求到php 我看框架里面写的是index.php?g=User&m=Store&a=test 这种格式的路径,但是我写这个路径的时候去发现没有走test方法,我现在在微信开发,通过file_put_content方法发现没有写文件来判断有没有走test方法的
URL模式是path_info模式还是你改了其他模式?发送post请求时,url可以用U方法来生成
你的项目有没有一个入口文件,在那个入口文件里定义你的项目名字,比如:define('APP_ROOT', '项目名');
有,但是我用的是define('APP_PATH','./weimicms/'); 用的是thinkphp 框架
用的是框架,那就好办了,TP里有个常量APP_NAME,在控制器里echo出来就是weimicms
再请教一个问题 ,现在我想用ajax post 请求到php 我看框架里面写的是index.php?g=User&m=Store&a=test 这种格式的路径,但是我写这个路径的时候去发现没有走test方法,我现在在微信开发,通过file_put_content方法发现没有写文件来判断有没有走test方法的
URL模式是path_info模式还是你改了其他模式?发送post请求时,url可以用U方法来生成
$.ajax({
type:"post",
dataType: "json",
url:"Coupon.php",
data:"data",
success:function(data){
alert(data);
alert("success");
},
error:function(data){
alert(data);
alert("error");
}
})
现在用ajax 请求 我不知道我怎么调用Coupon.php 中的test方法 我运行时已经执行alert("error")现在这两个php 在同一目录
你的项目有没有一个入口文件,在那个入口文件里定义你的项目名字,比如:define('APP_ROOT', '项目名');
有,但是我用的是define('APP_PATH','./weimicms/'); 用的是thinkphp 框架
用的是框架,那就好办了,TP里有个常量APP_NAME,在控制器里echo出来就是weimicms
再请教一个问题 ,现在我想用ajax post 请求到php 我看框架里面写的是index.php?g=User&m=Store&a=test 这种格式的路径,但是我写这个路径的时候去发现没有走test方法,我现在在微信开发,通过file_put_content方法发现没有写文件来判断有没有走test方法的
URL模式是path_info模式还是你改了其他模式?发送post请求时,url可以用U方法来生成
$.ajax({
type:"post",
dataType: "json",
url:"Coupon.php",
data:"data",
success:function(data){
alert(data);
alert("success");
},
error:function(data){
alert(data);
alert("error");
}
})
现在用ajax 请求 我不知道我怎么调用Coupon.php 中的test方法 我运行时已经执行alert("error")现在这两个php 在同一目录
不要用dataType:"json"这行
你不是用了 thinkphp 框架吗?
url:"Coupon.php", 这样就离开框架了,所有的工作都得自己完成
你不是用了 thinkphp 框架吗?
url:"Coupon.php", 这样就离开框架了,所有的工作都得自己完成
对,但是我不熟悉thinkphp框架,思维还停留在java,而且我用ndex.php?g=User&m=Coupon&a=test 没有办法访问到test这个方法
./ 同级目录
../ 上级目录
/ apache目录
如果你的thinkphp是3.2版本的话,U方法这样使用:
url : "{:U(MODULE_NAME . '/控制器名/控制器的方法名')}"比如"{:U(MODULE_NAME . '/User/index')}"
如果你的thinkphp是3.2版本的话,U方法这样使用:
url : "{:U(MODULE_NAME . '/控制器名/控制器的方法名')}"比如"{:U(MODULE_NAME . '/User/index')}"
因为我看其他页面是这样写的index.php?g=模块名&控制器名&a=方法名 比如index.php?g=Wap&m=Store&a=index
但是我的却不行,比如index.php?g=Wap&m=Toshake&a=test 有些控制名里面却是可以的,是需要配置吗或者说需要继承什么类
是我自己傻逼了,我在php的方法中没有加方法修饰符public,因为在java中肯定会提示的所以忽略了当成js脚本来写了 ,所以没有请求到,返回error ,之前一直把重心放到路径上了,index.php?g=Wap&m=Store&a=index这种方式是可以的,另外谢谢各位了,也希望以后有机会向你们学习。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
