/ 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.php
有include("../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
/
haveinclude("./user/codestart.php");
- All files in
/user/
haveinclude("codestart.php");
- All files in
/client/
haveinclude("../user/codestart.php");
The problem is that
/user/codestart.php
hasinclude("../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 beinclude("./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
最满意答案
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(Entity framework PostgreSQL)[2022-01-17]
实体框架也适用于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实体框架(POCO Entity Framework)[2021-12-18]
实际上POCO与.net世界中的POJO(Plain old java objects)类似。 POCO是不必遵循任何特定约定(实现任何接口,扩展任何类,具有特殊属性或命名约定等)的对象。 一些持久性框架迫使我们使用特定的接口或者attirbutes,抽象类。 只要你从头开始研究一个项目,并且你正在选择使用哪个框架,但是如果你正在使用遗留系统,并且想要改变其数据访问层以使用持久框架,那么这不是问题,它可能具有负面影响。 Actually POCO is similar to POJO (Plain old ... -
.NET实体框架(.NET Entity Framework)[2023-06-04]
我不明白为什么这是不好的做法。 根据您打算如何使用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 ...
-
对实体框架的怀疑(Doubts about entity framework)[2023-06-15]
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 ... -
实体框架4任何()(Entity Framework 4 Any())[2022-10-14]
最后得出的结论是,使用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. -
实体框架6多对多(Entity Framework 6 Many to many)[2023-10-18]
你永远不会将OrderItems添加到DbContext集合中。 你的代码也有问题,这意味着你多次覆盖你的项目和变量值。 下面的代码做了一些假设,因为你没有提供更多的代码,但应该很容易适应。 using (var context = new EFRecipesContext()) { var order = new Order { OrderId = 1, OrderDate = new DateTime(2010, 1, 18) }; context.Orders.Add(order); ... -
实体框架的方法不同(Entity Framework different approaches)[2022-08-09]
我们可以根据项目要求使用三种类型的实体框架方法。 数据库优先: 可以使用现有数据库 代码可以自动生成。 使用部分类/ T4模板可扩展 开发人员可以手动更新数据库 有一个非常好的设计器,它与下划线数据库同步 http://www.entityframeworktutorial.net/database-first-with-entity-framework.aspx 代码优先: 从守则完全控制模型; 没有EDMX /设计师 无需手动干预DB 该数据库仅用于数据 http://www.entityframewo ... -
实体框架加入(Entity Framework Join)[2023-04-09]
它应该看起来像: 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 = ... -
实体框架5多对多(Entity framework 5 many to many)[2022-07-07]
EF无法决定Course.Student或Course.Students引用Person.CoursesAttending 。 您必须给EF一个提示,例如使用[InverseProperty]上的[InverseProperty]属性: [InverseProperty("CoursesAttending")] public virtual ICollectionStudents { get; set; } 编辑 该模型将导致多个级联删除路径,即:当您删除一个Person时,连接表中的记 ...