0

我有一个旧文件。我想将它集成到我购买的新模板中。

我有一个链接列表。我将它们存储在 Session 数组中。每个数组都有一个标题和一个 url


<?php session_start();
//in my old file i write this

foreach ($_SESSION[links] as $value){
?>
<a href="<?php print $value[linkurl]?>"><?php print $value[linktitle]?></a ><?php
}

//  array style i need to match in the new file

//  "name" => array(
//      "title" => "Display Title",
//      "url" => "http://yoururl.com"
//      )

// what i tried

//  foreach ($_SESSION[links] as $value){
//      "$value[linktitle]" => array(
//          "title" => "$value[linktitle]",
//          "url" => "$value[linkurl]"
//      )
//  }

//obviously doesn't work
?>

这是完整的模板。我正在尝试替换 Smart UI 子(轮播、标签...)

<?php

//CONFIGURATION for SmartAdmin UI

//ribbon breadcrumbs config
//array("Display Name" => "URL");
$breadcrumbs = array(
    "Home" => APP_URL
);

/*navigation array config

ex:
"dashboard" => array(
    "title" => "Display Title",
    "url" => "http://yoururl.com",
    "url_target" => "_self",
    "icon" => "fa-home",
    "label_htm" => "<span>Add your custom label/badge html here</span>",
    "sub" => array() //contains array of sub items with the same format as the parent
)

*/
$page_nav = array(
    "dashboard" => array(
        "title" => "Dashboard",
        "url" => APP_URL,
    ),
    "smartui" => array(
        "title" => "Smart UI",
        "icon" => "fa-code",
        "sub" => array(

            "carousel" => array(
                "title" => "Carousel",
                "url" => APP_URL.'/smartui-carousel.php'
            ),
            "tab" => array(
                "title" => "Tab",
                "url" => APP_URL.'/smartui-tab.php'
            ),
            "accordion" => array(
                "title" => "Accordion",
                "url" => APP_URL.'/smartui-accordion.php'
            ),
            "widget" => array(
                'title' => "Widget",
                'url' => APP_URL."/smartui-widget.php"
            ),
            "datatable" => array(
                "title" => "DataTable",
                "url" => APP_URL."/smartui-datatable.php"
            ),
            "button" => array(
                "title" => "Button",
                "url" => APP_URL."/smartui-button.php"
            ),
            'smartform' => array(
                'title' => 'Smart Form',
                'url' => APP_URL.'/smartui-form.php'
            )
        )
    )

);

//configuration variables
$page_title = "";
$page_css = array();
$no_main_header = false; //set true for lock.php and login.php
$page_body_prop = array(); //optional properties for <body>
$page_html_prop = array(); //optional properties for <html>
?>

var_dump:

array(6) { 
    [0]=> array(4) { ["linktitle"]=> string(13) "Claims Center" ["linkurl"]=> string(79) "Claims.php" ["Sectionlinktitle"]=> string(12) "Applications" ["linkdes"]=> string(11) "Application" } 
    [1]=> array(4) { ["linktitle"]=> string(16) "Expense Allocate" ["linkurl"]=> string(81) "Expense.php" ["Sectionlinktitle"]=> string(12) "Applications" ["linkdes"]=> string(11) "Application" } 
    [2]=> array(4) { ["linktitle"]=> string(13) "Freight Rater" ["linkurl"]=> string(105) "User.php" ["Sectionlinktitle"]=> string(12) "Applications" ["linkdes"]=> string(11) "Application" } 
    [3]=> array(4) { ["linktitle"]=> string(14) "Invoice Center" ["linkurl"]=> string(71) "Online.php" ["Sectionlinktitle"]=> string(12) "Applications" ["linkdes"]=> string(11) "Application" } 
    [4]=> array(4) { ["linktitle"]=> string(4) "KPIs" ["linkurl"]=> string(4) "KPIs" ["Sectionlinktitle"]=> string(10) "Dashboards" ["linkdes"]=> string(9) "Dashboard" } 
    [5]=> array(4) { ["linktitle"]=> string(16) "Multi-Mode Rater" ["linkurl"]=> string(0) "M" ["Sectionlinktitle"]=> string(12) "Applications" ["linkdes"]=> string(16) "Multi-Mode Rater" }
            }
4

2 回答 2

1

您需要创建一个新数组:

$page_nav = array();
foreach ($_SESSION[links] as $value) {
    $page_nav[][$value['linktitle']] = array(
        'title' => $value['linktitle'],
        'url'   => $value['linkurl']
    )
}

现在您应该在新数组 $var; 中拥有所有内容。

于 2015-12-02T19:47:18.107 回答
1

您想将 $_SESSION['links'] 中的导航添加到新模板!

注释掉模板中的$page_nav变量 ( /* $page_nav = array( ... ); */)。这将生成要插入到模板中的代码(剪切和粘贴):

$a = $_SESSION['links'];
echo '<pre>$page_nav = array(' . "\n";
foreach( $a as $k=>$v ) {
    echo "\t'" . strtolower(str_replace(' ','',$v['linktitle'])) . "' => array(\n"
        . "\t\t'title' => '" . $v['linktitle'] . "',\n"
        . "\t\t'url' => '" . $v['linkurl'] . "'\n"
        . "\t),\n";
}
echo ');</pre>';

如果您想将代码保留在 $_SESSION 变量中(真的不是一个好主意),您可以将这段代码放在它的位置:

$page_nav = array();
foreach ( $_SESSION['links'] as $k=>$v ) {
    $page_nav[strtolower(str_replace(' ','',$v['linktitle']))] = array(
        'title' => $v['linktitle'],
        'url'   => $v['linkurl']
    );
}

我认为这应该工作!我没有考虑任何子菜单,因为您的 var_dump 中没有!

于 2015-12-03T16:17:23.603 回答