douzhang2680 2015-07-20 10:14
浏览 56
已采纳

包含一个公共文件只在一个文件Codeigniter中失败

i am including "navigation.php" which has the common menu in all my views .

<div id="navigation">
    <? include("navigation.php"); ?>
</div>

this code works in every other files but in one file it gives errors .

Severity: Warning
Message: include(navigation.php): failed to open stream: No such file or directory
Filename: views/readsinvo_index.php
Line Number: 2


Severity: Warning
Message: include(): Failed opening 'navigation.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php')
Filename: views/readsinvo_index.php
Line Number: 2

in "readsinvo_index.php" it is same as the other files

<div id="navigation">
    <? include("navigation.php"); ?>
</div>

and both the files are inside "views" . both files have permission 777 .

But when i tried with

<? include(dirname(__FILE__)."/navigation.php"); ?>

It works perfectly , but in all other pages , it is working when used

<? include("navigation.php"); ?>

is there any possible reason that i cannot include the file normally only in this file . I am using codeigniter framework and CentOS .

  • 写回答

2条回答 默认 最新

  • dongzai2952 2015-07-20 11:19
    关注

    You can use APPPATH

    APPPATH.'views/navigation.php'
    

    And Possible duplicate of how call another php file to Codeigniter view

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?