Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Routes
- <?php namespace Config;
- // Create a new instance of our RouteCollection class.
- $routes = Services::routes();
- // Load the system's routing file first, so that the app and ENVIRONMENT
- // can override as needed.
- if (file_exists(SYSTEMPATH . 'Config/Routes.php'))
- {
- require SYSTEMPATH . 'Config/Routes.php';
- }
- /**
- * --------------------------------------------------------------------
- * Router Setup
- * --------------------------------------------------------------------
- */
- $routes->setDefaultNamespace('App\Controllers');
- $routes->setDefaultController('Home');
- $routes->setDefaultMethod('index');
- $routes->setTranslateURIDashes(false);
- $routes->set404Override();
- $routes->setAutoRoute(true);
- /**
- * --------------------------------------------------------------------
- * Route Definitions
- * --------------------------------------------------------------------
- */
- $routes->get('/', 'Home::index');
- $routes->get('/about', 'Home::about');
- // Dashboard
- $routes->get('dashboard', function () {
- $data['title'] = "AdminLTE 3 | Dashboard";
- $data['breadcrumb_title'] = "Dashboard";
- $breadcrumb = array(
- array(
- 'title' => 'Home',
- 'link' => 'dashboard'
- ),
- array(
- 'title' => 'Dashboard v1',
- 'link' => null
- )
- );
- $data['breadcrumb'] = $breadcrumb;
- return view('dashboard/index', $data);
- });
- $routes->get('dashboard/v2', function () {
- $data['title'] = "AdminLTE 3 | Dashboard v2";
- $data['breadcrumb_title'] = "Dashboard v2";
- $breadcrumb = array(
- array(
- 'title' => 'Home',
- 'link' => 'dashboard'
- ),
- array(
- 'title' => 'Dashboard v2',
- 'link' => null
- )
- );
- $data['breadcrumb'] = $breadcrumb;
- return view('dashboard/v2', $data);
- });
- $routes->get('dashboard/v3', function () {
- $data['title'] = "AdminLTE 3 | Dashboard 3";
- $data['breadcrumb_title'] = "Dashboard v3";
- $breadcrumb = array(
- array(
- 'title' => 'Home',
- 'link' => 'dashboard'
- ),
- array(
- 'title' => 'Dashboard v3',
- 'link' => null
- )
- );
- $data['breadcrumb'] = $breadcrumb;
- return view('dashboard/v3', $data);
- });
- //-------------------------------------------------
- $routes->get('dashboard/v4', function () {
- $data['title'] = "AdminLTE 3 | Dashboard 4";
- $data['breadcrumb_title'] = "Dashboard v4a";
- $breadcrumb = array(
- array(
- 'title' => 'Home',
- 'link' => 'dashboard'
- ),
- array(
- 'title' => 'Dashboard v4',
- 'link' => null
- )
- );
- $data['breadcrumb'] = $breadcrumb;
- return view('dashboard/v4', $data);
- });
- //-------------------------------------------------
- /*$routes->get('crud/index',function () { |
- $data = []; |
- $data['title']="AdminLTE 3 | Dashboard 4"; |
- $data['breadcrumb_title']="User List"; |
- $breadcrumb=array( |
- array( |
- 'title' => 'Home', |
- 'link' => 'dashboard' | delete this and
- ), |
- array( |
- 'title' => 'User list', |
- 'link' => null |
- ) |
- ); |
- $data['breadcrumb']=$breadcrumb; |
- return view('crud/index',$data); |
- });*/ |
- $routes->get('crud/index', 'Users::index'); <====== replace
- //-------------------------------------------------
- //-------------------------------------------------
- # Controller
- public function index()
- {
- $data = [];
- $data['users']=$this->uModel->findAll();
- $data['title']="AdminLTE 3 | Dashboard 4";
- $data['breadcrumb_title']="User List";
- $breadcrumb=array(
- array(
- 'title' => 'Home',
- 'link' => 'dashboard'
- ),
- array(
- 'title' => 'User list',
- 'link' => null
- )
- );
- $data['breadcrumb']=$breadcrumb;
- return view('crud/index',$data);
- }
- //-------------------------------------------------
- # Model
- <?php namespace App\Models;
- use CodeIgniter\Model;
- class UserModel extends Model
- {
- protected $table = 'users';
- protected $primaryKey = 'id';
- protected $returnType = 'array';
- protected $useSoftDeletes = true;
- protected $allowedFields = ['uniId', 'fname', 'lname', 'uname', 'email', 'password', 'created_at', 'updated_at', 'status', 'profile_pic', 'activation_date'];
- protected $useTimestamps = true;
- protected $createdField = 'created_at';
- protected $updatedField = 'updated_at';
- protected $deletedField = 'deleted_at';
- protected $validationRules = [
- 'fname' => 'required|alpha_numeric_space|min_length[3]',
- 'lname' => 'required|alpha_numeric_space|min_length[3]',
- 'uname' => 'required|alpha_numeric_space|min_length[3]',
- 'email' => 'required|valid_email|is_unique[users.email]',
- 'password' => 'required|min_length[6]',
- 'cpass' => 'required_with[password]|matches[password]',
- ];
- protected $validationMessages = [
- 'email' => [
- 'is_unique' => 'Sorry, that email already exist, choose another.',
- 'required' => 'Email is required.',
- 'valid_email' => 'Please enter a valid email address.',
- ]
- ];
- protected $skipValidation = false;
- }
- //-------------------------------------------------
- # Page
- <?= $this->extend('layouts/master') ?>
- <?= $this->section('head') ?>
- <?= $this->endSection() ?>
- <?= $this->section('foot') ?>
- <?= $this->endSection() ?>
- <?= $this->section('content') ?>
- <div class="container">
- <div class="row">
- <div class="col-md-10">
- <?php if(count($users) > 0): ?>
- <table class="table">
- <tr>
- <th>Id</th>
- <th>Name</th>
- <th>Surname</th>
- <th>Username</th>
- <th>Email</th>
- <th>Created</th>
- <th>Modified</th>
- <th>Pic</th>
- </tr>
- <?php foreach ($users as $user): ?>
- <tr>
- <td><?=$user->id;?></td>
- <td><?=$user->fname;?></td>
- <td><?=$user->lname;?></td>
- <td><?=$user->uname;?></td>
- <td><?=$user->email;?></td>
- <td><?=$user->created_at;?></td>
- <td><?=$user->updated_at;?></td>
- <td><?=$user->profile_pic;?></td>
- </tr>
- <?php endforeach; ?>
- </table>
- <?php else: ?>
- <h3>Sorry, no data found.</h3>
- <?php endif; ?>
- </div>
- </div>
- </div>
- <?= $this->endSection() ?>
Add Comment
Please, Sign In to add comment