I have a code I am developing but now I'm Stuck as I'm new to PHP.
When I use simple quotation marks it works but, I think this code is a little ugly and strange, I would like someone to review.
Code:
<?php echo"
<li class='light-blue'>
<a data-toggle='dropdown' href='#' class='dropdown-toggle'>
<img class='nav-user-photo' src='../upload/avatar/$arqDir'>".$_SESSION['img'].">
<span class='user-info'>
<small>Bem Vindo,</small>
echo ".$_SESSION['nome'].";
</span>
<i class='ace-icon fa fa-caret-down'></i>
</a>
<ul class='user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close'>
<li>
<a href='#'>
<i class='ace-icon fa fa-cog'></i>
Cofigurações
</a>
</li>
<li>
<a href='profile.html'>
<i class='ace-icon fa fa-user'></i>
Perfil
</a>
</li>
<li class='divider'></li>
<li>
<a href='logout.php'>
<i class='ace-icon fa fa-power-off'></i>
Sair
</a>
</li>
</ul>
</li>";
?>
As AbraCadaver said, this is one way it could be done:
<li class="light-blue">
<a data-toggle="dropdown" href="#" class="dropdown-toggle">
<img class="nav-user-photo" src="../upload/avatar/<?php echo $arqDir . "/" . $_SESSION['img'];?>">
<span class="user-info">
<small>Bem Vindo,</small>
<?php echo $_SESSION['nome']; ?>
</span>
<i class="ace-icon fa fa-caret-down"></i>
</a>
<ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
<li>
<a href="#">
<i class="ace-icon fa fa-cog"></i>
Cofigurações
</a>
</li>
<li>
<a href="profile.html">
<i class="ace-icon fa fa-user"></i>
Perfil
</a>
</li>
<li class="divider"></li>
<li>
<a href="logout.php">
<i class="ace-icon fa fa-power-off"></i>
Sair
</a>
</li>
</ul>
</li>
And another way could be:
<?php
echo '
<li class="light-blue">
<a data-toggle="dropdown" href="#" class="dropdown-toggle">
<img class="nav-user-photo" src="../upload/avatar/'. $arqDir . '/' . $_SESSION['img'].'">
<span class="user-info">
<small>Bem Vindo,</small>
'.$_SESSION['nome'].'
</span>
<i class="ace-icon fa fa-caret-down"></i>
</a>
<ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
<li>
<a href="#">
<i class="ace-icon fa fa-cog"></i>
Cofigurações
</a>
</li>
<li>
<a href="profile.html">
<i class="ace-icon fa fa-user"></i>
Perfil
</a>
</li>
<li class="divider"></li>
<li>
<a href="logout.php">
<i class="ace-icon fa fa-power-off"></i>
Sair
</a>
</li>
</ul>
</li>';
In order to remove any confusion, use double quotes in your echo statements and use necessary escaping. For example
echo "<div class=\"boy\"> </div>";
OR
echo"<li class=\"boy\"> </li>";
The class name 'boy' was with double quotes too , so we just escaped it with backlash.
In case when you want to use arrays you just need to close and open quotes when required. For example
echo "The user is: ".$row['user'].":";
The above line will output something like:
The user is: user:
<?php echo"
<li class=\"light-blue\">
<a data-toggle=\"dropdown\" href=\"#\" class=\"dropdown-toggle\">
<img class=\"nav-user-photo\" src=\"../upload/avatar/$arqDir\"".$_SESSION['img'].">
<span class=\"user-info\">
<small>Bem Vindo,</small>
".$_SESSION['nome'].";
</span>
<i class=\"ace-icon fa fa-caret-down\"></i>
</a>
<ul class=\"user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close\">
<li>
<a href=\"#\">
<i class=\"ace-icon fa fa-cog\"></i>
Cofigurações
</a>
</li>
<li>
<a href=\"profile.html\">
<i class=\"ace-icon fa fa-user\"></i>
Perfil
</a>
</li>
<li class=\"divider\"></li>
<li>
<a href=\"logout.php\">
<i class=\"ace-icon fa fa-power-off\"></i>
Sair
</a>
</li>
</ul>
</li>";
?>
I have tried to review and edit code accordingly. I hope you get this.
Three method as I know is:
1. <?php echo $variable; ?>
2.
<?php
echo " $variable ";
?>
3.
<?php
echo <<< LINK
$variable
LINK;
...
?>
I prefered third solutions. In my opinion is the most clear.
In your case should looks like:
echo <<< html
<li class='light-blue'>
<a data-toggle='dropdown' href='#' class='dropdown-toggle'>
<img class='nav-user-photo' src='../upload/avatar/$arqDir'>$_SESSION[img]>
<span class='user-info'>
<small>Bem Vindo,</small>
$_SESSION[nome]
</span>
<i class='ace-icon fa fa-caret-down'></i>
</a>
<ul class='user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close'>
<li>
<a href='#'>
<i class='ace-icon fa fa-cog'></i>
Cofigurações
</a>
</li>
<li>
<a href='profile.html'>
<i class='ace-icon fa fa-user'></i>
Perfil
</a>
</li>
<li class='divider'></li>
<li>
<a href='logout.php'>
<i class='ace-icon fa fa-power-off'></i>
Sair
</a>
</li>
</ul>
</li>
html;
Related
hope you are all doing well, i have just face a problem. i make my website online. everything working well expect navbar toggler icon. it is not working on mobile device. it is working well on desktop
here is my code
<nav class="navbar navbar-expand-md navbar-light bg-light sticky-top">
<div class="container-fluid">
<a class="navbar-brand" href="index.php"><img src="./assests/images/logo.png" class="logo ml-5" alt="file not found" /> </a>
<button class="navbar-toggler " type="button" role="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"> </span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item <?php if($page == 'home') echo 'active' ?>">
<a class="nav-link " href="index.php"><i class="mr-2 fas fa-home"> </i>Home </a>
</li>
<li class="nav-item <?php if($page == 'about') echo 'active' ?>">
<a class="nav-link" href="about.php"><i class="mr-2 fas fa-users"> </i> About Us</a>
</li>
<li class="nav-item dropdown <?php if($page == 'products') echo 'active' ?>" >
<a class="nav-link dropdown-toggle dropdown-toggle-split" href="products.php" data-toggle="dropdown" id="dropedownMenuButton"aria-expanded="false" aria-hospopup="true" >
<i class="mr-2 fas fa-wrench"> </i>Products
</a>
<ul class="dropdown-menu" aria-labelledby="dropedownMenuButton">
<li class="list-group-item">
<a class="dropdown-item" href="bolts-screws.php"> Bolts/Screws </a>
</li>
<li class="list-group-item">
<a class="dropdown-item" href="nuts.php"> Nuts </a>
</li>
<li class="list-group-item">
<a class="dropdown-item" href="washers.php"> Washers </a>
</li>
<li class="list-group-item">
<a class="dropdown-item" href="screws.php"> Screws </a>
</li>
<li class="list-group-item">
<a class="dropdown-item" href="socket-bolt-screws.php"> Socket Bolts/Screws </a>
</li>
<li class="list-group-item">
<a class="dropdown-item" href="anchor-fastener.php"> Anchor Fasteners </a>
</li>
</ul>
</li>
<li class="nav-item <?php if($page == 'connect') echo 'active' ?>">
<a class="nav-link" href="connect.php"><i class="mr-2 fas fa-user"> </i> Contact us </a>
</li>
</ul>
</div>
</div>
</nav>
you can check my website also
http://rudrafasteners.com/
It seems you don't add Javascript at your head. Add the followings lines to your HTML <head> tag (Jquery and Bootstrap JS):
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
I am trying to use AdminLTE3 as admin panel in laravel and I have nav-item links which doesn't activate when I click them. I don't know how to fix this. I used the starter.html from adminLTE3 and I have all the required assets for adminLTE3 but my nav-item links are not activated, How can I fix this, I would really appreciate for any help. my side bar code is :
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<!-- Add icons to the links using the .nav-icon class
with font-awesome or any other icon font library -->
<li class="nav-item has-treeview menu-open">
<a href="#" class="nav-link active">
<i class="nav-icon fa fa-tachometer-alt"></i>
<p>
Dashboard
<i class="right fa fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="{{route('home')}}" class="nav-link">
<i class="fab fa-elementor nav-icon"></i>
<p>Main</p>
</a>
</li>
</ul>
</li>
<li class="nav-item has-treeview">
<a href="#" class="nav-link">
<i class="nav-icon fa fa-book"></i>
<p>
Posts
<i class="right fa fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="{{route('posts.index')}}" class="nav-link">
<i class="nav-icon fa fa-book"></i>
<p>All Posts</p>
</a>
</li>
</ul>
</li>
<li class="nav-item has-treeview">
<a href="#" class="nav-link">
<i class="nav-icon fa fa-strikethrough"></i>
<p>
Services
<i class="right fa fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="{{route('services.index')}}" class="nav-link">
<i class="fa fa-asterisk nav-icon"></i>
<p>All Service</p>
</a>
</li>
</ul>
</li>
<li class="nav-item">
<a href="{{route('gallery.index')}}" class="nav-link">
<i class="nav-icon fa fa-th"></i>
<p>
Galleries
</p>
</a>
</li>
<li class="nav-item">
<a href="{{route('logout')}}" class="nav-link">
<i class="nav-icon fa fa-code"></i>
<p>
Logout
</p>
</a>
</li>
</ul>
</nav>
I tried the suggestion provided by kapitan
nav-link {{ Route::current()->getName() == 'posts.index' ? 'active' : '' }}
but problem is when I click any nav-item it hides like this
when I click the service drop down then it shows like this
For simplicity sake:
<a href="#" class="nav-link {{ Route::current()->getName() == 'my.route.name' ? 'active' : '' }}">
As you can see, this is a long cut method, you can improve this further. But this is a good starting point for you.
UPDATE:
Untested, but can you please try this:
<a href="#" class="nav-link {{ Request::is('my/url','my/url/*') ? 'active' : '' }}">
UPDATE 2 :
<li class="nav-item has-treeview {{ Request::is('my/url','my/url/*') ? 'active' : '' }}">
<a href="#" class="nav-link">
<i class="nav-icon fa fa-strikethrough"></i>
<p>
Services
<i class="right fa fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview {{ Request::path() == 'my/url/here' ? 'menu-open' : '' }}">
<li class="nav-item">
<a href="{{route('services.index')}}" class="nav-link {{ Request::is('my/url/here') ? 'active' : '' }}">
<i class="fa fa-asterisk nav-icon"></i>
<p>All Service</p>
</a>
</li>
</ul>
</li>
I am working with the older version of Laravel and I don't which version I am working on as this project was given to me for debugging. I have zero knowledge of Laravel. Doing php artisan --version gave me this as an output in git bash
Following is the code:
<nav class="sidebar sidebar-offcanvas" id="sidebar">
<ul class="nav">
<li class="nav-item nav-profile">
<div class="nav-link">
<div class="user-wrapper">
<div class="text-wrapper">
<p class="profile-name"><?php echo GetUserDetail::get(Session::get('admin_id'),'fullname');?> <span class="status-indicator online"></span></p>
</div>
</div>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="dashboard" style="background-color: #518be6 !important; width:250px; color: #fff !important; border-radius: 0px;">
<i class="fas fa-tachometer-alt menu-icon" style="color: #fff"></i>
<span class="menu-title">ड्याशबोर्ड</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="service">
<i class="fas fa-briefcase menu-icon"></i>
<span class="menu-title">सेवाहरू</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="resource">
<i class="fab fa-osi menu-icon"></i>
<span class="menu-title">संसाधन</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="agenda">
<i class="fab fa-forumbee menu-icon"></i>
<span class="menu-title">परियोजना</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="profile">
<i class="fas fa-people-carry menu-icon"></i>
<span class="menu-title">प्रोफाइल</span>
</a>
</li> <li class="nav-item">
<a class="nav-link" href="notice">
<i class="fas fa-info-circle menu-icon"></i>
<span class="menu-title">सूचना तथा जानकारी</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="add_user">
<i class="fas fa-user-plus menu-icon"></i>
<span class="menu-title">थप प्रयोगकर्ता</span>
</a>
</li>
</ul>
</nav>
I tried keeping / just before href like href="/dashboard". My expected output is http://demo.com/admin/dashboard but when I click on the link it goes like this http://demo.com/dashboard.
I also tried doing href="{{ url('dashboard')}}" which converts my URL to like this:
http://demo.com/admin/%7B%7B%20url('dashboard')%7D%7D
What should be done to fix this?
Your short fix would be this,
href="/admin/dashboard"
The problem was with the way html use href attribute. When you put '/' (forward slash) at the very beginning it starts from the root directory not from the current directory.
However this is a bad practice. You should study routing method and url generation . For large project your url controller will be much easier.
(I don't know your version of laravel. So I provided the link of the latest version. But you can change it from menu.)
I have directory like this "localhost/site/folder1/file.php", I need to access file.php from "site" directory this way
href = "folder1/file.php"
unfortunately it takes me to
href = "folder1/folder1/file.php"
and when I access "index.php" file located in "site" directory from "folder1", this way
href = "../index.php"
it takes me to root directory in c: I mean this way
href = "localhost/index.php".
I have stacked with this problem for two days now, please any one to help me get out this.
Note: I am using bootstrap framework
More edit...
here is the full code.
<section>
<section class="hbox stretch">
<!-- .aside -->
<aside class="bg-black dk nav-xs aside hidden-print" id="nav">
<section class="vbox">
<section class="w-f-md scrollable">
<div class="slim-scroll" data-height="auto" data-disable-fade-out="true" data-distance="0" data-size="10px" data-railOpacity="0.2">
<!-- nav -->
<nav class="nav-primary hidden-xs">
<ul class="nav bg clearfix" data-ride="collapse">
<!--<li class="hidden-nav-xs padder m-t m-b-sm text-xs text-muted">
Discover
</li>-->
<li>
<a href= "../index.php">
<i class="icon-home icon text-success"></i>
<span class="font-bold">Home</span>
</a>
</li>
<li>
<a href="#" class="auto">
<span class="pull-right text-muted">
<i class="fa fa-angle-left text"></i>
<i class="fa fa-angle-down text-active"></i>
</span>
<i class="icon-music-tone-alt icon text-info"></i>
<span class="font-bold">Audios</span>
</a>
<ul class="nav dk text-sm">
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Speaches</span>
</a>
</li>
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Preaches</span>
</a>
</li>
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Interviews</span>
</a>
</li>
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Songs</span>
</a>
</li>
</ul>
</li>
<li>
<a href="#" class="auto">
<span class="pull-right text-muted">
<i class="fa fa-angle-left text"></i>
<i class="fa fa-angle-down text-active"></i>
</span>
<i class="icon-book-open icon text-primary-lter"></i>
<span class="font-bold">Writtings</span>
</a>
<ul class="nav dk text-sm">
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Books</span>
</a>
</li>
<li >
<a href="../general.php" class="auto">
<i class="fa fa-angle-right text-xs"></i>
<span>Jounals</span>
</a>
</li>
</ul>
</li>
<li>
<a href="#">
<i class="icon-users icon text-primary-lter"></i>
<span class="font-bold">Artists</span>
</a>
</li>
<li>
<a href="#">
<i class="icon-film icon text-info-dker"></i>
<span class="font-bold">Albums</span>
</a>
</li>
<li class="m-b hidden-nav-xs"></li>
</ul>
<ul class="nav" data-ride="collapse">
<li class="hidden-nav-xs padder m-t m-b-sm text-xs text-muted">
User Account
</li>
<li>
<?php
if(!isset ($_SESSION['email'])){
echo "
<a href='../signin.php' class='auto'>
<i class='icon-login icon'>
</i>
<span>Signin</span>
</a>
</li>
<li >
<a href='../signup.php' class='auto'>
<i class='fa fa-smile-o'>
</i>
<span>Signup</span>
</a>
</li>
";
}else{
echo "
<a href='../signout.php' class='auto'>
<i class='icon-logout icon'>
</i>
<span>SignOut</span>
</a>
</li>";
if (!isset($_SESSION['admin_name'])) {
echo "
<li >
<a href='profile.php' class='auto'>
<i class='fa fa-smile-o'>
</i>
<span>My profile</span>
</a>
</li>
";
}else{
echo "
<li >
<a href='MembersManagement.php' class='auto'>
<i class='fa fa-edit'>
</i>
<span>Manage Member</span>
</a>
</li>
<li >
<a href='admin.php' class='auto'>
<i class='fa fa-edit'>
</i>
<span>My Dashboard</span>
</a>
</li>
";
}
}
?>
</ul>
</nav>
<!-- / nav ---->
</div>
</section>
And the problem is on this line
<nav class="nav-primary hidden-xs">
When I remove "nav-primary" everything is doing fine with the anchors () but it changes the appearance and arrangements in the section, what should I do, I am new to bootstrap frameworks.
If you are having problem with relative urls, you can try doing with absolute urls like :
href = "localhost/site/folder1/file.php".
and for the other one you can do same:
href = "localhost/site/index.php
Maybe this helps.
i am trying to make my navigation dynamic but i' having a few problems. here is my code.
<?php
if (stristr($_SERVER["SCRIPT_NAME"], "index.php")) {
echo '<li class="active">
<a href="index.php">
<span class="meta">
<span class="text">HOME</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
} else{
echo '<li>
<a href="index.php">
<span class="meta">
<span class="text">HOME</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
}
?>
<?php
if (stristr($_SERVER["SCRIPT_NAME"], "services.php")) {
echo '<li class="dropdown active">
<a href="#" class="dropdown-toggle " data-toggle="dropdown">
<span class="meta">
<span class="text">SERVICES</span>
<span class="caret"></span>
</span>
</a>
<ul class="dropdown-menu">
<li>Service A</li>
<li>Service B</li>
<li>Service C</li>
<li>Service D</li>
</ul>
</li>';
} else{
echo '<li class="dropdown">
<a class="dropdown-toggle " data-toggle="dropdown">
<span class="meta">
<span class="text">SERVICES</span>
<span class="caret"></span>
</span>
</a>
<ul class="dropdown-menu">
<li>Service A</li>
<li>Service B</li>
<li>Service C</li>
<li>Service D</li>
</ul>
</li>';
}
?>
<?php
if (stristr($_SERVER["SCRIPT_NAME"], "data-catalog.php")) {
echo '<li class="active">
<a href="data-catalog.php">
<span class="meta">
<span class="text">DATA CATALOG</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
} else{
echo '<li>
<a href="data-catalog.php">
<span class="meta">
<span class="text">DATA CATALOG</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
}
?>
<?php
if (stristr($_SERVER["SCRIPT_NAME"], "about.php")) {
echo '<li class="active">
<a href="about.php">
<span class="meta">
<span class="text">ABOUT US</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
} else{
echo '<li>
<a href="about.php">
<span class="meta">
<span class="text">ABOUT US</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
}
?>
<?php
if (stristr($_SERVER["SCRIPT_NAME"], "contact.php")) {
echo '<li class="active">
<a href="contact.php">
<span class="meta">
<span class="text">CONTACT US</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
} else{
echo '<li>
<a href="contact.php">
<span class="meta">
<span class="text">CONTACT US</span>
<!--<span class="caret"></span>-->
</span>
</a>
</li>';
}
?>
After running, i realise that on the home page, the services list drops down successfully but it doesnt do so when i'm on other pages. Can anybody help me?
I think the code and its structure is perfect. There is nothing absolute wrong with the code. Just uploaded the files onto the web and everything is working perfect. I checked plugins and all and i realised that the file only needs to be on the internet to run smoothly.