首页 \ 问答 \ / vs。/ vs ../以及绝对和相对路径的问题(Trouble with / vs ./ vs ../ and absolute and relative paths)

/ vs。/ vs ../以及绝对和相对路径的问题(Trouble with / vs ./ vs ../ and absolute and relative paths)

我有很多PHP文件

/
/client/
/user/
/config/
etc...

我希望我的所有文件都包含/user/codestart.php 。 (很多功能等)

因此:

  • /所有文件都include("./user/codestart.php");
  • /user/所有文件都include("codestart.php");
  • /client/所有文件都include("../user/codestart.php");

问题是/user/codestart.phpinclude("../config/config.php"); (MySQL ID和密码)

/ /index.php的文件(例如/index.php )包含./user/codestart.php 。 然后/user/codestart.php包含../config/config.php ,但它看不到它,因为它认为它是从/而不是从/user/调用它。

如果我将include("../config/config.php")更改为include("./config/config.php") ,将其修复为/ files,但将其分解为/user//client/ files。

底线是,当一个PHP文件包含另一个文件时,PHP认为它是从原始文件的位置操作,而不是调用文件。

我需要使用相对路径,而不是绝对路径。 绝对路径在我的情况下不起作用。

有什么方法可以解决这个问题吗?


I have many PHP files in

/
/client/
/user/
/config/
etc...

I want all my files to include /user/codestart.php. (Lots of functions etc)

Therefore:

  • All files in / have include("./user/codestart.php");
  • All files in /user/ have include("codestart.php");
  • All files in /client/ have include("../user/codestart.php");

The problem is that /user/codestart.php has include("../config/config.php"); (The MySQL ID and password)

When a file in / runs, such as /index.php, it includes ./user/codestart.php. Then /user/codestart.php includes ../config/config.php, but it cannot see it, because it thinks it is calling it from /, instead of from /user/.

If I change include("../config/config.php") to be include("./config/config.php") that fixes it for / files, but breaks it for/user/ and/client/ files.

Bottom line is that when one PHP file includes another file, PHP thinks it is operating from the location of the original file, not the calling file.

I need to use relative paths, not absolute paths. Absolute paths will not work in my situation.

Is there any way to solve this?


原文:https://stackoverflow.com/questions/7098139
更新时间:2021-08-22 20:08

最满意答案

1)是的。

http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx

2)也是的。 一切都是通过DbContext类完成的。 它允许您访问数据库,并根据需要执行SQL。 但是对于刚开始,您只需使用LINQ来查询您的DbSet。


1) Yes.

http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx

2) Also yes. Everything is done through a DbContext class. It allows you to access the Database, and execute SQL if you wish. But for starting out you will simply just use LINQ to query your DbSets.

相关问答

更多
  • 实体框架也适用于Postgresql的Npgsql - .Net数据提供程序。 有关如何设置的教程可以在这里找到: http : //npgsql.projects.postgresql.org/ Entity framework also works with Npgsql - .Net Data Provider for Postgresql. A tutorial on how to set it up can be found here: http://www.npgsql.org/ef6/inde ...
  • 实际上POCO与.net世界中的POJO(Plain old java objects)类似。 POCO是不必遵循任何特定约定(实现任何接口,扩展任何类,具有特殊属性或命名约定等)的对象。 一些持久性框架迫使我们使用特定的接口或者attirbutes,抽象类。 只要你从头开始研究一个项目,并且你正在选择使用哪个框架,但是如果你正在使用遗留系统,并且想要改变其数据访问层以使用持久框架,那么这不是问题,它可能具有负面影响。 Actually POCO is similar to POJO (Plain old ...
  • 我不明白为什么这是不好的做法。 根据您打算如何使用EF对象,这可能会很尴尬。 我有部分类在EF对象中实现BIZ逻辑,使用接口提供抽象级别。 例如。 public partial class Client : IClient { void DoSomething(); } // then an EF generated object ... public partial class Client { // ... } 我唯一遇到的问题是序列化对象。 在我的情况下,使用WCF序列化成JSON。 没有 ...
  • 我以前做过这个: 1)获取数据库的副本 2)创建相关的外键 3)从您的副本创建实体框架模型 4)更改连接字符串以指回“实时”数据库。 一个很好的选择是首先使用反向工程代码来创建数据库的代码第一版。 然后,您可以在代码中手动添加关系。 I've done this before: 1) Take a copy of the database 2) Create the relevant foreign keys 3) Create the entity framework model from your co ...
  • 1)是的。 http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx 2)也是的。 一切都是通过DbContext类完成的。 它允许您访问数据库,并根据需要执行SQL。 但是对于刚开始,您只需使用LINQ来查询您的DbSet。 1) Yes. http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-a ...
  • 最后得出的结论是,使用EF 5.0上的.Any()不会转化为存在于Oracle 11g中 - 解决方案是直接调用并返回yes或no。 Finally came to a conclusion is that using .Any() on EF 5.0 does not translate to exist in Oracle 11g - solution was to do a direct call and bring back yes or no.
  • 你永远不会将OrderItems添加到DbContext集合中。 你的代码也有问题,这意味着你多次覆盖你的项目和变量值。 下面的代码做了一些假设,因为你没有提供更多的代码,但应该很容易适应。 using (var context = new EFRecipesContext()) { var order = new Order { OrderId = 1, OrderDate = new DateTime(2010, 1, 18) }; context.Orders.Add(order); ...
  • 我们可以根据项目要求使用三种类型的实体框架方法。 数据库优先: 可以使用现有数据库 代码可以自动生成。 使用部分类/ T4模板可扩展 开发人员可以手动更新数据库 有一个非常好的设计器,它与下划线数据库同步 http://www.entityframeworktutorial.net/database-first-with-entity-framework.aspx 代码优先: 从守则完全控制模型; 没有EDMX /设计师 无需手动干预DB 该数据库仅用于数据 http://www.entityframewo ...
  • 它应该看起来像: from pa in db.personnelAllowedDates join pi in db.PersonnelInformation on pa.personelId equals pi.personelId select new AnObjectDefinedByYou { PersonelId = pa.personelId, AllowedDatesId = pa.allowedDatesId, //... PersonnelNumber = ...
  • EF无法决定Course.Student或Course.Students引用Person.CoursesAttending 。 您必须给EF一个提示,例如使用[InverseProperty]上的[InverseProperty]属性: [InverseProperty("CoursesAttending")] public virtual ICollection Students { get; set; } 编辑 该模型将导致多个级联删除路径,即:当您删除一个Person时,连接表中的记 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)