开发者

nested include in php

The directory structure:

  • C:/wamp/www/application/model/data_access/data_object.php

  • C:/wamp/www/application/model/users/user.class.php

  • C:/wamp/www/application/controller/projects.php

  • C:/wamp/www/application/controller/links/links.php

I have 2 php files data_object.php and user.class.php Now user.class.php has an include statement for data_object.php wchih is relative to user.class.php.These two files are under different directory hierarchy. Now I have to include this user.class.php in various files (like projects.php, links.php-which themselves are under different hierarchy) whenever i want to create a User() object.

The problem is the relative path for file inclusion of data_object.php does work for say projects.php but if i open links.php the error message says it could not open file data_object.php in user.class.php. What i think is for relative inclusion of data_开发者_运维百科object.php it is considering the path of the file in which user.class.php is included. I am facing such problems in more than one scenarios

I have to keep my directory structure the way it is but have to find a way to work with nested includes. I used Document root of session it give root path as C:/wamp/www/ i appended the path for data_object.php include but this is not working. (note: the forward slash is present after www) I am currently running on wamp server's localhost but after completion i have to host the solution on a domain. Pls help


as far as i remember, relative paths will use the top-level php for includes, ie and include that includes another include the path should be relative to the first php file.

I went down this relative path, which i regret, I would strongly recommend what Pekka suggested and using an absolute path like this

ps add some libe breaks to your question!


We use an autoloader (spl_autoload_register) that indexes classes (with token_get_all)
It's a some work before it starts working, but with a autoloader, you just start using classes.

It heavily reduces the number of includes (and include issues)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜