0

ナビゲーションに次のタブがあります。

<li<?php if ($thisPage=="Customers") echo " class=\"current\""; ?>><a href="/customers/">Customers</a></li>
<li<?php if ($thisPage=="Trunks")  echo " class=\"current\""; ?>><a href="/trunks/">Trunks</a></li>
<li<?php if ($thisPage=="Settings")  echo " class=\"current\""; ?>><a href="/settings/">Settings</a></li>   

そして、管理者がログインしているときにのみ表示したい:

if ($_COOKIE['custid'] == "admin") {

echo "Customers";
echo "Trunks";
echo "Settings";

}

これらのスクリプトの 2 つをどのように組み合わせることができますか???

4

3 に答える 3

1

「admin in cookie」の問題を別の問題として扱う...

<?php if($admin): ?>
    <li<?php if ($thisPage=="Customers"): ?> class="current"<?php endif; ?>><a href="/customers/">Customers</a></li>
    <li<?php if ($thisPage=="Trunks"): ?> class="current"<?php endif; ?>><a href="/trunks/">Trunks</a></li>
    <li<?php if ($thisPage=="Settings"): ?> class="current"<?php endif; ?>><a href="/settings/">Settings</a></li>
<?php endif; ?>

PHP のインライン構文は、{} を使用するよりもはるかに優れており、html 内でエコーします

于 2010-05-19T23:14:46.060 に答える
0

あなたが何を意味するのか正確にはわかりませんが、

<?php
if ($_COOKIE['custid'] == "admin") { ?>
 <li<?php if ($thisPage=="Customers") echo " class=\"current\""; ?>><a href="/customers/">Customers</a></li>
 <li<?php if ($thisPage=="Trunks")  echo " class=\"current\""; ?>><a href="/trunks/">Trunks</a></li>
 <li<?php if ($thisPage=="Settings")  echo " class=\"current\""; ?>><a href="/settings/">Settings</a></li>
<?php } else { ?>
 <li><a href="/customers/">Customers</a></li>
 <li><a href="/trunks/">Trunks</a></li>
 <li><a href="/settings/">Settings</a></li>
<?php } ?>

// OR

<li<?php if ($_COOKIE['custid'] == "admin" && $thisPage=="Customers") echo " class=\"current\""; ?>><a href="/customers/">Customers</a></li>
<li<?php if ($_COOKIE['custid'] == "admin" && $thisPage=="Trunks")  echo " class=\"current\""; ?>><a href="/trunks/">Trunks</a></li>
<li<?php if ($_COOKIE['custid'] == "admin" && $thisPage=="Settings")  echo " class=\"current\""; ?>><a href="/settings/">Settings</a></li>

そして、投稿自体のコメントで@webdestroyaに同意します。管理者のステータスを確認するには、Cookie の代わりにセッションなどを使用する必要があります。例のためにここでは変更しませんでした。

于 2010-05-19T23:05:50.887 に答える
0
<?php
if ($_COOKIE['custid'] == "admin") { ?>
<li<?php if ($thisPage=="Customers") echo " class=\"current\""; ?>><a href="/customers/">Customers</a></li>
<li<?php if ($thisPage=="Trunks")  echo " class=\"current\""; ?>><a href="/trunks/">Trunks</a></li>
<li<?php if ($thisPage=="Settings")  echo " class=\"current\""; ?>><a href="/settings/">Settings</a></li>
<?php } ?>

かなり簡単です、それを他のものの中に入れてください...

于 2010-05-19T23:10:13.637 に答える