search

请问如何获取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这种方式是可以的,另外谢谢各位了,也希望以后有机会向你们学习。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram APIIntroduction to the Instagram APIMar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!