Skip to content

Commit 301aa97

Browse files
committed
RELEASE 4.0.0 reusing code and inherit common controller for check
* a main controller do the check work of the sesion at `webappweb/core/CP_Controller.php` that all controllers inherit * so `$this->checksession();` is common functionality and reusable code in the rest of controllers
1 parent 0280c25 commit 301aa97

File tree

5 files changed

+48
-27
lines changed

5 files changed

+48
-27
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ its necesary to provide functionality, and `$rs_access` is the result of the DB
6565
Since version 3.0.0 a imap mail layer was added so an extra files are at `webappweb/libraries/Imap.php`
6666
and `webappweb/config/imap.php`, `$im_access` is the result of the mail login check.
6767

68+
Since version 4.0.0 a main controller do the check work of the sesion at `webappweb/core/CP_Controller.php`
69+
that all controllers inherit, so `$this->checksession();` is common functionality and reusable code.
70+
6871
#### Process simple login
6972

7073
This is the main entry controller, it will load the views of login form page

webappweb/config/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
| https://codeigniter.com/userguide3/general/creating_libraries.html
120120
|
121121
*/
122-
$config['subclass_prefix'] = 'MY_';
122+
$config['subclass_prefix'] = 'CP_';
123123

124124
/*
125125
|--------------------------------------------------------------------------

webappweb/controllers/Indexauth.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
22

3-
class Indexauth extends CI_Controller {
4-
5-
private $sessobj;
3+
class Indexauth extends CP_Controller {
64

75
function __construct()
86
{
97
parent::__construct();
10-
$this->load->helper(array('form', 'url','html'));
11-
$this->load->library('table');
12-
$this->load->library('session');
13-
$this->sessobj = $this->session->userdata('userdata');
14-
$this->output->enable_profiler(TRUE);
158
}
169

1710
/** http://127.0.0.1/codeigniterpower/index.php/indexcontroler/index */

webappweb/controllers/Indexhome.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
22

3-
class Indexhome extends CI_Controller {
4-
5-
private $sessobj;
3+
class Indexhome extends CP_Controller {
64

75
function __construct()
86
{
97
parent::__construct();
10-
$this->load->helper(array('form', 'url','html'));
11-
$this->load->library('table');
12-
$this->load->library('session');
13-
$this->sessobj = $this->session->userdata('userdata');
14-
$this->output->enable_profiler(TRUE);
8+
$this->checksession();
159
}
1610

1711
/** http://127.0.0.1/codeigniterpower/index.php/indexcontroler/index */
1812
public function index()
1913
{
20-
if($this->sessobj == NULL)
21-
{
22-
redirect('Indexauth');
23-
return;
24-
}
2514
$data = array();
2615
$data['viewtitle'] = 'index at Pagetest';
2716
$this->load->view('header.php',$data);
@@ -31,11 +20,6 @@ public function index()
3120

3221
public function testfunct()
3322
{
34-
if($this->sessobj == NULL)
35-
{
36-
redirect('Indexauth');
37-
return;
38-
}
3923
$data = array();
4024
$data['viewtitle'] = 'testfunc at Pagetest';
4125
$this->load->view('header.php',$data);

webappweb/core/CP_Controller.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* webappweb Application Controller Class
5+
*
6+
* @author PICCORO lenz McKAY <mckaygerhard>
7+
* @copyright Copyright (c) 2016, 2019
8+
* @version ac - 1.1
9+
*/
10+
class CP_Controller extends CI_Controller
11+
{
12+
13+
private $sessobj;
14+
15+
public function __construct()
16+
{
17+
parent::__construct();
18+
19+
if(ENVIRONMENT !== 'production')
20+
$this->output->enable_profiler(TRUE);
21+
22+
$this->load->helper(array('form', 'url','html'));
23+
$this->load->library('table');
24+
$this->load->library('session');
25+
26+
}
27+
28+
/** revision de session, si invalidad redirige a login */
29+
public function checksession()
30+
{
31+
$this->sessobj = $this->session->userdata('userdata');
32+
33+
if($this->sessobj == NULL)
34+
{
35+
redirect('Indexauth');
36+
return;
37+
}
38+
}
39+
40+
}
41+

0 commit comments

Comments
 (0)