I have a big problem with loading a set of views twice. Doing that, the Stylesheets are not loaded.
What I want to do is:
On a successful login, the views ...
·header (which contains the links for the stylesheets) ·submit (which contains a form to be submitted by a button) ·footer
... are loaded by the contoller. The stylesheets works fine.
When I click the button of view submit, the submitting of the appropriate form calls the controller function get_data().
This function get_data() should finaly load the views..
·header ·submit ·footer
... again and additional the content view (after the submit view). But this leads to my problem. The views are loaded but without the entire stylesheets.
Does someone have an idea to solve the problem ?
The Controller:
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
// load form helper and validation library
$this->load->helper('form','array');
$this->load->library('form_validation');
// set validation rules
$this->form_validation->set_rules('username', 'Username', 'required|alpha_numeric');
$this->form_validation->set_rules('password', 'Password', 'required');
$data->title = 'Login';
if ($this->form_validation->run() == false) {
// validation not ok, send validation errors to the view
$this->load->view('header');
$this->load->view('user/login/login');
$this->load->view('footer');
} else {
// set variables from the form
$username = $this->input->post('username');
$password = $this->input->post('password');
if ($this->user_model->resolve_user_login($username, $password)) {
I don't fully understand the flow of your application, but I suggest to redirect to another url after a succesful login.
Otherwise, the url will remain user/login, and I wonder if that's what you want.
In general, on succesful login, a user is redirected to the home page, or some other page that tells the user he is logged in now.
Also consider using some kind of rendering function in a MY_Controller class.
Example:
PHP Code:
protected function render_page($view,$data=array()) { $this->load->view('theme/header'); $this->load->view($view,$data); $this->load->view('theme/footer'); }
Now, in your controller, you just need this code to load a specific view:
PHP Code:
$this->render_page('login');
This will load the header view, then the login view, and finally the footer view.
(02-04-2018, 10:52 AM)Wouter60 Wrote: I don't fully understand the flow of your application, but I suggest to redirect to another url after a succesful login.
Otherwise, the url will remain user/login, and I wonder if that's what you want.
In general, on succesful login, a user is redirected to the home page, or some other page that tells the user he is logged in now.
Also consider using some kind of rendering function in a MY_Controller class.
Example:
PHP Code:
protected function render_page($view,$data=array()) { $this->load->view('theme/header'); $this->load->view($view,$data); $this->load->view('theme/footer'); }
Now, in your controller, you just need this code to load a specific view:
PHP Code:
$this->render_page('login');
This will load the header view, then the login view, and finally the footer view.
My code is only an example how I understand CodeIgniter. I attached a graphic, which shows my idea how the MVC of CodeIgniter works. Hope you understand my intensions. When I am wrong, please tell me
You really should be using a MY_Controller because you can separate
your backend form your frontend etc;
Save as: ./application/core/MY_Controller.php
PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/** * ----------------------------------------------------------------------- * Editor : PhpStorm * Date : 1/12/2018 * Time : 7:40 AM * Authors : Raymond L King Sr. * ----------------------------------------------------------------------- * * Class MY_Controller * * @project ci3admin * @author Raymond L King Sr. * @link http://www.procoversfx.com * @copyright Copyright (c) 2009 - 2018 Custom Software Designers, LLC. * @license http://www.procoversfx.com/license * ----------------------------------------------------------------------- */
/** * Class BaseController */ class BaseController extends CI_Controller { /** * Class properties - public, private, protected and static. * ----------------------------------------------------------------------- */
/** * Data variable for views. * * @var array */ public $data = [];
/** * __construct () * ----------------------------------------------------------------------- * * Class Constructor * * NOTE: Not needed if not setting values or extending a Class. */ public function __construct() { parent::__construct();
log_message('debug', "Base Controller Class Initialized"); }
/** * Class Backend */ class Backend extends BaseController { /** * Class properties - public, private, protected and static. * ----------------------------------------------------------------------- */
/** * __construct () * ----------------------------------------------------------------------- * * Class Constructor * * NOTE: Not needed if not setting values or extending a Class. */ public function __construct() { parent::__construct();
log_message('debug', "Backend Controller Class Initialized"); }
/** * Class Frontend */ class Frontend extends BaseController { /** * Class properties - public, private, protected and static. * ------------------------------------------------------------------- */
/** * __construct () * ------------------------------------------------------------------- * * Class Constructor * * NOTE: Not needed if not setting values or extending a Class. */ public function __construct() { parent::__construct();
log_message('debug', "Frontend Controller Class Initialized"); }
Then extend all of your other controllers with either ( Backend or Frontend )
Like so:
Save as: ./application/controllers/admin/Users.php
PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/** * ----------------------------------------------------------------------- * Editor : PhpStorm * Date : 2/3/2018 * Time : 7:34 AM * Authors : Raymond L King Sr. * ----------------------------------------------------------------------- * * Class Users * * @project ci3admin * @author Raymond L King Sr. * @link http://www.procoversfx.com * @copyright Copyright (c) 2009 - 2018 Custom Software Designers, LLC. * @license http://www.procoversfx.com/license * ----------------------------------------------------------------------- */
class Users extends Backend { /** * Class properties - public, private, protected and static. * ----------------------------------------------------------------------- */
/** * __construct () * ----------------------------------------------------------------------- * * Class Constructor * * NOTE: Not needed if not setting values or extending a Class. */ public function __construct() { parent::__construct();
// restrict this controller to admins only $this->auth->restrict('admin');
log_message('debug', "Users Controller Class Initialized"); }
/** * index () * ----------------------------------------------------------------------- * */ public function index() {
}
/** * add () * ------------------------------------------------------------------- * * */ public function add() {
}
/** * edit () * ------------------------------------------------------------------- * * */ public function edit() {
}
/** * retrieve () * ------------------------------------------------------------------- * * */ public function retrieve() {
}
/** * delete () * ------------------------------------------------------------------- * * @param int $id */ public function delete(int $id) { $this->db->where('id', $id) ->delete('users');
$this->render('users/delete_success'); }
/** * manage () * ------------------------------------------------------------------- * * Manage users in the users database table. * */ public function manage() { $this->load->library('table');
$data = $this->db->get('users');
$result = $data->result_array();
// Setting headings for the table $this->table->set_heading('Username', 'Email', 'Actions');