Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php CMS,代码在index.php中运行,但在更深层的CMS项目文件夹中无法运行_Php_Content Management System_Recurrence - Fatal编程技术网

php CMS,代码在index.php中运行,但在更深层的CMS项目文件夹中无法运行

php CMS,代码在index.php中运行,但在更深层的CMS项目文件夹中无法运行,php,content-management-system,recurrence,Php,Content Management System,Recurrence,我有一个简单的递归函数,可以将数组值输出到网页。如果我从cms3\index.php使用它,它将非常有效。但是如果我从cms34\ww.admin\pages\menu.php使用它,它在第一轮中只能部分工作 我正在翻阅这本书: 使用PHP和jQuery进行CMS设计, 在第三章中,他们给出了简单的CMS示例 下面的脚本应该读取数据库并生成指向两个网页的超链接 // cms34\ww.admin\pages\menu.php <?php echo '<div id="pages-wr

我有一个简单的递归函数,可以将数组值输出到网页。如果我从cms3\index.php使用它,它将非常有效。但是如果我从cms34\ww.admin\pages\menu.php使用它,它在第一轮中只能部分工作

我正在翻阅这本书: 使用PHP和jQuery进行CMS设计, 在第三章中,他们给出了简单的CMS示例

下面的脚本应该读取数据库并生成指向两个网页的超链接

// cms34\ww.admin\pages\menu.php
<?php
echo '<div id="pages-wrapper">';
$rs=dbAll('select id,type,name,parent from pages order by ord,name');
$pages=array();
foreach($rs as $r){
    if(!isset($pages[$r['parent']]))$pages[$r['parent']]=array();
    $pages[$r['parent']][]=$r;
}
function show_pages($id,$pages){
    if(!isset($pages[$id]))return;
    echo '<ul>';
    foreach($pages[$id] as $page){
        echo '<li id="page_'.$page['id'].'"><a href="pages.php?id='.$page['id'].'">';
        echo '<ins>&nbsp;</ins>'.htmlspecialchars($page['name']).'</a>';
        show_pages($page['id'],$pages);
        echo '</li>';
    }
    echo '</ul>';
}
show_pages(0,$pages);
echo '</div>';
这是网页的外观:

 rs=Array ( [0] => Array ( [id] => 24 [type] => 0 [name] => Home [parent] => 0 ) [1] => Array ( [id] => 35 [type] => 0 [name] => Home2 [parent] => 0 ) [2] => Array ( [id] => 36 [type] => 0 [name] => test [parent] => 24 ) [3] => Array ( [id] => 38 [type] => 0 [name] => test3 [parent] => 24 ) [4] => Array ( [id] => 25 [type] => 0 [name] => Second Page [parent] => 0 ) )
in menu.php before if r=Array ( [id] => 24 [type] => 0 [name] => Home [parent] => 0 )
in menu.php after if r=Array ( [id] => 24 [type] => 0 [name] => Home [parent] => 0 ) ;;r[parent][0]=0
in menu.php before if r=Array ( [id] => 35 [type] => 0 [name] => Home2 [parent] => 0 )
in menu.php after if r=Array ( [id] => 35 [type] => 0 [name] => Home2 [parent] => 0 ) ;;r[parent][0]=0
in menu.php before if r=Array ( [id] => 36 [type] => 0 [name] => test [parent] => 24 )
in menu.php after if r=Array ( [id] => 36 [type] => 0 [name] => test [parent] => 24 ) ;;r[parent][0]=2
in menu.php before if r=Array ( [id] => 38 [type] => 0 [name] => test3 [parent] => 24 )
in menu.php after if r=Array ( [id] => 38 [type] => 0 [name] => test3 [parent] => 24 ) ;;r[parent][0]=2
in menu.php before if r=Array ( [id] => 25 [type] => 0 [name] => Second Page [parent] => 0 )
in menu.php after if r=Array ( [id] => 25 [type] => 0 [name] => Second Page [parent] => 0 ) ;;r[parent][0]=0
in menu.php function show_pages, $id =0
in menu.php function show_pages, $pages =Array ( [0] => Array ( [0] => Array ( [id] => 24 [type] => 0 [name] => Home [parent] => 0 ) [1] => Array ( [id] => 35 [type] => 0 [name] => Home2 [parent] => 0 ) [2] => Array ( [id] => 25 [type] => 0 [name] => Second Page [parent] => 0 ) ) [24] => Array ( [0] => Array ( [id] => 36 [type] => 0 [name] => test [parent] => 24 ) [1] => Array ( [id] => 38 [type] => 0 [name] => test3 [parent] => 24 ) ) )
in menu.php function show_pages, $pages[$id] =Array ( [0] => Array ( [id] => 24 [type] => 0 [name] => Home [parent] => 0 ) [1] => Array ( [id] => 35 [type] => 0 [name] => Home2 [parent] => 0 ) [2] => Array ( [id] => 25 [type] => 0 [name] => Second Page [parent] => 0 ) ) 
如您所见,数据是从数据库中提取的。但是循环函数show_pages$id,$pages不会在第二轮执行。我的意思是显示页面功能的这部分没有执行:

  foreach($pages[$id] as $page){
            print_r('<br> in menu.php foreach ').print_r(htmlspecialchars($page['name']));
        echo '<li id="page_'.$page['id'].'"><a href="pages.php?id='.$page['id'].'">';
        echo '<ins>&nbsp;</ins>'.htmlspecialchars($page['name']).'</a>';
        show_pages($page['id'],$pages);
        echo '</li>';
    }

In CMS i go to:
http://localhost/cms34/ww.admin/index.php
which requires 'pages.php';
which requires 'header.php' and 'pages/menu.php';

the header.php requires 'admin_libs.php',
which requires require $_SERVER['DOCUMENT_ROOT'].'/cms34/ww.incs/basics.php';
which has __autoload, and DB connection functions.
然后执行递归函数生成超链接

如果我将pages/menu.php中的所有内容复制到cms34\index.php 和前置行:

//this line included file for DB connention and data retrieving functions
    require $_SERVER['DOCUMENT_ROOT'].'/cms34/ww.incs/basics.php';
超链接已生成,递归函数正在运行。
但是,如果我尝试使用CMS中的cms34\ww.admin\pages\menu.php代码,它将无法工作。

它开始工作时没有任何原因。不知道为什么,但它昨天不工作。如果有人能解释原因以及如何比等一天更快地解决问题,我将不胜感激

$rs=dbAll('select id,type,name,parent from pages order by ord,name');
//this line included file for DB connention and data retrieving functions
    require $_SERVER['DOCUMENT_ROOT'].'/cms34/ww.incs/basics.php';