You are currently viewing CodeIgniter tutorials for beginners Hindi me part-6

CodeIgniter tutorials for beginners Hindi me part-6

Hello friends, CodeIgniter ke part-6 me aapaka swagat hai. Aaj ham home page ka thoda kam karlete hai kya bolate ho. dosto ek help chahiye aapki muje thoda confusion horaha ki konsa project shuru kare ham. eccomerce ya social media ka jaise fb. yaa fir blog banaye post comment. blog banate hai kya bolate ho aajkal trend me bhi hai. Aap muje comment karke jarur bataye please.

Chalo aaj ham home page ke function hide or show ka kam karte hai. jaise user login hai to hame register or login hide karke logout dikhana padega. waise hi login nahi hai to logout chupana padega hai na. or user ka name bhi dikhayenge database se nikal ke header me corner pe, jaise sab sites me hota hai.

Dekho abhi sab visible hai.

show hide ke liye ham session ka use karenge. hamane login or register ke time id store ki thi na? wahi use karna hai if else statement me. agar id hai to logout dikhao or nahi hai to login register. simple hai na.

<?php if($this->session->userdata('id')) : ?>
          <li class="nav-item">
            <a class="nav-link" href="<?php echo site_url('logout'); ?>">Logout</a>
          </li>
        <?php else : ?>
          <li class="nav-item">
            <a class="nav-link" href="<?php echo site_url('login'); ?>">Login</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="<?php echo site_url('regiser'); ?>">Regiser</a>
           </li>
        <?php endif; ?>

bus itana karna hai home me kam hojayega. kuch doubt hai aap muje comment kar sakte hai. chaliye ab name display karate hai. isake liye hame controller me jana padega. per hame header me hi dikhana or baki sab page pe bhi dikhana hai to her function me use call karna padega. isaliye ham header me hi database call karlete hai short me. or ham ek or icon style bhi add karenge font awesome isake bare me to pata hoga? ye bhi bahut mast chiz hai. her type ke icon mill jate hai yeha bus hame link stysheet cdn add karna hai. ye CDN link hai online kam karta hai. aap agar ise ofline use karna chahte hai to bhi add kar sakte hai download karke. https://fontawesome.com/how-to-use/on-the-web/setup/hosting-font-awesome-yourself

How to use icon in coding

<i class="fas fa-user"></i> <!-- uses solid style -->
  <i class="far fa-user"></i> <!-- uses regular style -->
  <i class="fal fa-user"></i> <!-- uses light style -->
  <!--brand icon-->
  <i class="fab fa-github-square"></i> <!-- uses brands style -->

Online CDN for Font Awesome

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">

For Offline Font Awesome

<link rel="stylesheet" href="<? php echo site_url('your-path-to-fontawesome/js/all.js'); ?>">

friends, aapko font awesome downlod karke apane project me dall de or fir uska path upart your path to me dalde fir ye offline bhi kam karega. waise online bhi achha hi chalta hai. dekho hide show or user name display karane ka kam hogaya hai dosto or mene username ke aage icon bhi display karaya hai.

chalo ab ham register controller me logout function bana dete hai.

Register Controller

public function logout()
	{
		$this->session->unset_userdata('id');
		redirect('/');
	}

or dosto route php me ye kam bhi karna padega yaad hai na link short karne ka route php config folder me jo hai

$route['logout']['GET'] = 'register/logout';

hogaya log out bhi doston.

header php Views

<?php
defined('BASEPATH') OR exit('No direct script access allowed'); 
$quary = $this->db->select('*')
         ->where('ID',$this->session->userdata('id'))
         ->get('users');
if($quary->num_rows()){
  $FullName = $quary->row()->FullName;
}

?>
<!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">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
    <title>Hello, world!</title>
  </head>
  <body>
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
  <a class="navbar-brand" href="#">Hello World!</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="<?php echo site_url('/'); ?>">Home <span class="sr-only">(current)</span></a>
      </li>
        <?php if($this->session->userdata('id')) : ?>
          <li class="nav-item">
            <a class="nav-link" href="<?php echo site_url('logout'); ?>">Logout</a>
          </li>
        <?php else : ?>
          <li class="nav-item">
            <a class="nav-link" href="<?php echo site_url('login'); ?>">Login</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="<?php echo site_url('regiser'); ?>">Regiser</a>
           </li>
        <?php endif; ?>
      
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
    </ul>
    <?php if($this->session->userdata('id')) : ?>
      <ul class="navbar-nav">
          <li class="nav-item">
            <a class="nav-link" href="#"><i class="fa fa-user" aria-hidden="true"></i> <?php echo $FullName; ?></a>
          </li>
      </ul>
    <?php endif; ?>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>
  <div class="container">

dosto chaliye aaj ke liye itana hi. aapko kuch bhi doubt ho. kuch bhi help chahiye aap muje comment kar sakte hai.

happy coding

This Post Has One Comment

Leave a Reply