chiabgigi

adminlte-ci4

Feb 1st, 2021 (edited)
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.01 KB | None | 0 0
  1. # Routes
  2. <?php namespace Config;
  3.  
  4. // Create a new instance of our RouteCollection class.
  5. $routes = Services::routes();
  6.  
  7. // Load the system's routing file first, so that the app and ENVIRONMENT
  8. // can override as needed.
  9. if (file_exists(SYSTEMPATH . 'Config/Routes.php'))
  10. {
  11.     require SYSTEMPATH . 'Config/Routes.php';
  12. }
  13.  
  14. /**
  15.  * --------------------------------------------------------------------
  16.  * Router Setup
  17.  * --------------------------------------------------------------------
  18.  */
  19. $routes->setDefaultNamespace('App\Controllers');
  20. $routes->setDefaultController('Home');
  21. $routes->setDefaultMethod('index');
  22. $routes->setTranslateURIDashes(false);
  23. $routes->set404Override();
  24. $routes->setAutoRoute(true);
  25.  
  26. /**
  27.  * --------------------------------------------------------------------
  28.  * Route Definitions
  29.  * --------------------------------------------------------------------
  30.  */
  31. $routes->get('/', 'Home::index');
  32. $routes->get('/about', 'Home::about');
  33.  
  34.  
  35. // Dashboard
  36. $routes->get('dashboard', function () {
  37.     $data['title'] = "AdminLTE 3 | Dashboard";
  38.     $data['breadcrumb_title'] = "Dashboard";
  39.     $breadcrumb =   array(
  40.                         array(
  41.                             'title' => 'Home',
  42.                             'link' => 'dashboard'
  43.                         ),
  44.                         array(
  45.                             'title' => 'Dashboard v1',
  46.                             'link' => null
  47.                         )
  48.                     );
  49.     $data['breadcrumb'] = $breadcrumb;
  50.     return view('dashboard/index', $data);
  51. });
  52.  
  53. $routes->get('dashboard/v2', function () {
  54.     $data['title'] = "AdminLTE 3 | Dashboard v2";
  55.     $data['breadcrumb_title'] = "Dashboard v2";
  56.     $breadcrumb =   array(
  57.                         array(
  58.                             'title' => 'Home',
  59.                             'link' => 'dashboard'
  60.                         ),
  61.                         array(
  62.                             'title' => 'Dashboard v2',
  63.                             'link' => null
  64.                         )
  65.                     );
  66.     $data['breadcrumb'] = $breadcrumb;
  67.     return view('dashboard/v2', $data);
  68. });
  69.  
  70. $routes->get('dashboard/v3', function () {
  71.     $data['title'] = "AdminLTE 3 | Dashboard 3";
  72.     $data['breadcrumb_title'] = "Dashboard v3";
  73.     $breadcrumb =   array(
  74.                         array(
  75.                             'title' => 'Home',
  76.                             'link' => 'dashboard'
  77.                         ),
  78.                         array(
  79.                             'title' => 'Dashboard v3',
  80.                             'link' => null
  81.                         )
  82.                     );
  83.     $data['breadcrumb'] = $breadcrumb;
  84.     return view('dashboard/v3', $data);
  85. });
  86. //-------------------------------------------------
  87. $routes->get('dashboard/v4', function () {
  88.     $data['title'] = "AdminLTE 3 | Dashboard 4";
  89.     $data['breadcrumb_title'] = "Dashboard v4a";
  90.     $breadcrumb =   array(
  91.         array(
  92.             'title' => 'Home',
  93.             'link' => 'dashboard'
  94.         ),
  95.         array(
  96.             'title' => 'Dashboard v4',
  97.             'link' => null
  98.         )
  99.     );
  100.     $data['breadcrumb'] = $breadcrumb;
  101.     return view('dashboard/v4', $data);
  102. });
  103. //-------------------------------------------------
  104. /*$routes->get('crud/index',function () {           |
  105.     $data = [];                                     |
  106.     $data['title']="AdminLTE 3 | Dashboard 4";      |
  107.     $data['breadcrumb_title']="User List";          |
  108.     $breadcrumb=array(                              |
  109.         array(                                      |
  110.             'title' => 'Home',                      |
  111.             'link' => 'dashboard'                   | delete this and
  112.         ),                                          |
  113.         array(                                      |
  114.             'title' => 'User list',                 |
  115.             'link' => null                          |
  116.         )                                           |
  117.     );                                              |
  118.     $data['breadcrumb']=$breadcrumb;                |
  119.     return view('crud/index',$data);                |
  120. });*/                                               |
  121. $routes->get('crud/index', 'Users::index');           <======  replace
  122. //-------------------------------------------------
  123.  
  124. //-------------------------------------------------
  125.  
  126. # Controller
  127.    public function index()
  128.     {
  129.         $data = [];
  130.         $data['users']=$this->uModel->findAll();
  131.  
  132.         $data['title']="AdminLTE 3 | Dashboard 4";
  133.         $data['breadcrumb_title']="User List";
  134.         $breadcrumb=array(
  135.             array(
  136.                 'title' => 'Home',
  137.                 'link' => 'dashboard'
  138.             ),
  139.             array(
  140.                 'title' => 'User list',
  141.                 'link' => null
  142.             )
  143.         );
  144.         $data['breadcrumb']=$breadcrumb;
  145.  
  146.         return view('crud/index',$data);
  147.     }
  148.  
  149. //-------------------------------------------------
  150.  
  151. # Model
  152. <?php namespace App\Models;
  153.  
  154. use CodeIgniter\Model;
  155.  
  156. class UserModel extends Model
  157. {
  158.     protected $table      = 'users';
  159.     protected $primaryKey = 'id';
  160.  
  161.     protected $returnType = 'array';
  162.     protected $useSoftDeletes = true;
  163.  
  164.     protected $allowedFields = ['uniId', 'fname', 'lname', 'uname', 'email', 'password', 'created_at', 'updated_at', 'status', 'profile_pic', 'activation_date'];
  165.  
  166.     protected $useTimestamps = true;
  167.     protected $createdField  = 'created_at';
  168.     protected $updatedField  = 'updated_at';
  169.     protected $deletedField  = 'deleted_at';
  170.  
  171.     protected $validationRules    = [
  172.         'fname'         => 'required|alpha_numeric_space|min_length[3]',
  173.         'lname'         => 'required|alpha_numeric_space|min_length[3]',
  174.         'uname'         => 'required|alpha_numeric_space|min_length[3]',
  175.         'email'         => 'required|valid_email|is_unique[users.email]',
  176.         'password'      => 'required|min_length[6]',
  177.         'cpass'         => 'required_with[password]|matches[password]',
  178.     ];
  179.     protected $validationMessages = [
  180.         'email' => [
  181.             'is_unique'     => 'Sorry, that email already exist, choose another.',
  182.             'required'      => 'Email is required.',
  183.             'valid_email'   => 'Please enter a valid email address.',
  184.         ]
  185.     ];
  186.     protected $skipValidation     = false;
  187. }
  188.  
  189. //-------------------------------------------------
  190.  
  191. # Page
  192. <?= $this->extend('layouts/master') ?>
  193.  
  194. <?= $this->section('head') ?>
  195. <?= $this->endSection() ?>
  196.  
  197. <?= $this->section('foot') ?>
  198. <?= $this->endSection() ?>
  199.  
  200. <?= $this->section('content') ?>
  201.     <div class="container">
  202.         <div class="row">
  203.             <div class="col-md-10">
  204.                 <?php if(count($users) > 0): ?>
  205.  
  206.                 <table class="table">
  207.                     <tr>
  208.                         <th>Id</th>
  209.                         <th>Name</th>
  210.                         <th>Surname</th>
  211.                         <th>Username</th>
  212.                         <th>Email</th>
  213.                         <th>Created</th>
  214.                         <th>Modified</th>
  215.                         <th>Pic</th>
  216.                     </tr>
  217.                     <?php foreach ($users as $user): ?>
  218.                         <tr>
  219.                             <td><?=$user->id;?></td>
  220.                             <td><?=$user->fname;?></td>
  221.                             <td><?=$user->lname;?></td>
  222.                             <td><?=$user->uname;?></td>
  223.                             <td><?=$user->email;?></td>
  224.                             <td><?=$user->created_at;?></td>
  225.                             <td><?=$user->updated_at;?></td>
  226.                             <td><?=$user->profile_pic;?></td>
  227.                         </tr>
  228.                     <?php endforeach; ?>
  229.                 </table>
  230.                 <?php else: ?>
  231.                     <h3>Sorry, no data found.</h3>
  232.                 <?php endif; ?>
  233.             </div>
  234.         </div>
  235.     </div>
  236.  
  237. <?= $this->endSection() ?>
  238.  
Add Comment
Please, Sign In to add comment