我通过自举建立了一个网站,现在我正试图使其更具活力。我要完成的过程不是使用引导程序。我真的很想念这件事吗?请您看看我的代码吗?
(我不想用代码重载这篇文章,所以只显示nav.php和array.php)我已经将nav.php包含在<nav></nav>
和array.php中的头文件中。非常高。
任何帮助将不胜感激-我才刚刚开始自己的旅程,所以请像我不太懂的那样对我轻描淡写,因为这是真的,我不是! :-)
//nav.php which I took out of the header
<a class="navbar-brand" href="index.html">Harrisons Hair & Beauty</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav">
<?php
foreach($navItems as $item){
echo "<li class=\"nav-item\">
<a class=\"nav-link\" href=\"$item[slug]\">$item[title]</a>
</li>";
}
?>
</ul>
</div>
// array.php
<?php
$navItems = [
[
slug => "index.php"
title => "Home"
],
[
slug => "about.php",
title => "About"
],
[
slug => "gallery.php",
title => "Gallery"
],
[
slug => "other.php",
title => "Other Services"
],
[
slug => "contact.php",
title => "Find Us"
],
[
slug => "test.php",
title => "Test Page"
]
];
?>
答案 0 :(得分:0)
要在echo语句中串联字符串,可以使用
import asyncio
import websockets
conn = websockets.connect('ws://127.0.0.1:8000/ws/registration/123')
conn.send('hello')
或echo "..." . $item['slug'] . "..."
。还要确保echo "... {$item['slug']} ..."
数组的声明在$navItems
输出语句之前。
祝你好运。
答案 1 :(得分:0)
您的数组格式错误。将“”中的键包装起来,并在“ index.php”后面添加一个逗号。同样,将foreach($navItems as $item){
更改为foreach($navItems as $key => $item){
,以获取嵌套的数组值(导航项)。
通过这些调整,您的代码可以正常工作。
<!doctype html>
<html lang="en">
<head>
<!-- required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- Libraries - jQuery first, then Popper.js, then Bootstrap.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<?php
$navItems = [
[ // keys (i.e. slug and title) need surrounding ""
"slug" => "index.php", // missing comma
"title" => "Home"
],
[
"slug" => "about.php",
"title" => "About"
],
[
"slug" => "gallery.php",
"title" => "Gallery"
],
[
"slug" => "other.php",
"title" => "Other Services"
],
[
"slug" => "contact.php",
"title" => "Find Us"
],
[
"slug" => "test.php",
"title" => "Test Page"
]
];
?>
<!-- nav.php which I took out of the header -->
<a class="navbar-brand" href="index.html">Harrisons Hair & Beauty</a>
<button style = "color: #0000FF !important; border: 1px solid blue !important;" class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
toggle menu<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav">
<?php
foreach($navItems as $key => $item){
echo "<li class=\"nav-item\" style='color: #FFFFFF !important;'>
<a class=\"nav-link\" href=\"$item[slug]\">$item[title]</a>
</li>";
}
?>
</ul>
</div>
</body>
</html>