Я скачал исходный код с здесь .
, теперь у меня есть следующий шаблон
- application / views / template / footer. php
- application / views / template / header-guest. php
- application / views / template / header-user. php
- application / views / template / site- css. php
- application / views / template / site- js. php application / views / home. php
Я хочу домашняя страница (приложение / контроллеры / Home. php)
Показать для пользователя
- $ this-> load-> view ('template / header-user');
- $ this-> load-> view ('home');
- $ this-> load-> view ('template / footer');
- $ this -> load-> view ('template / site- CSS');
- $ this-> load-> view ('template / site- JavaScript');
И показать для гостя
- $ this-> load-> view ('template / header-guest');
- $ this-> load-> view (' home ');
- $ this-> load-> view (' template / footer ');
- $ this-> load-> view ('template / site- CSS');
- $ this-> load-> view ('template / site- JavaScript');
Как мне это настроить?
User_Profile_Model. php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class User_Profile_Model extends CI_Model
{
public function getprofile($userid)
{
$query = $this->db->select('firstName,lastName,emailId,mobileNumber,regDate')
->where('id', $userid)
->from('tblusers')
->get();
return $query->row();
}
public function update_profile($fname, $lname, $mnumber, $userid)
{
$data = array(
'firstName' => $fname,
'lastName' => $lname,
'mobileNumber' => $mnumber,
);
$sql_query = $this->db->where('id', $userid)
->update('tblusers', $data);
}
}
User_Login_Model. php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class User_Login_Model extends CI_Model
{
public function validatelogin($emailid, $password, $status)
{
$query = $this->db->where(['emailId' => $emailid, 'userPassword' => $password]);
$account = $this->db->get('tblusers')->row();
if ($account != null) {
$dbstatus = $account->isActive;
//verifying status
if ($dbstatus == $status) {
return $account->id;
} else {
return null;
$this->session->set_flashdata('error', 'Your accounis is not active contact admin');
redirect('login');
}
}
return null;
}
}
Панель инструментов. php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Dashboard extends CI_Controller
{
public function __construct()
{
parent::__construct();
if (!$this->session->userdata('uid')) {
redirect('user/login');
}
}
public function index()
{
$userid = $this->session->userdata('uid');
$this->load->model('User_Profile_Model');
$profiledetails = $this->User_Profile_Model->getprofile($userid);
$this->load->view('template/header-user', ['profile' => $profiledetails]);
$this->load->view('user/dashboard', ['profile' => $profiledetails]);
$this->load->view('template/footer');
$this->load->view('template/site-css');
$this->load->view('template/site-js');
}
}
User_profile. php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class User_profile extends CI_Controller
{
public function __construct()
{
parent::__construct();
if (!$this->session->userdata('uid')) {
redirect('user/login');
}
$this->load->model('User_Profile_Model');
}
public function index()
{
$userid = $this->session->userdata('uid');
$profiledetails = $this->User_Profile_Model->getprofile($userid);
$this->load->view('user/user_profile', ['profile' => $profiledetails]);
}
public function updateprofile()
{
$this->form_validation->set_rules('firstname', 'First Name', 'required|alpha');
$this->form_validation->set_rules('lastname', 'Last Name', 'required|alpha');
$this->form_validation->set_rules('mobilenumber', 'Mobile Number', 'required|numeric|exact_length[10]');
if ($this->form_validation->run()) {
$fname = $this->input->post('firstname');
$lname = $this->input->post('lastname');
$mnumber = $this->input->post('mobilenumber');
$userid = $this->session->userdata('uid');
$this->User_Profile_Model->update_profile($fname, $lname, $mnumber, $userid);
$this->session->set_flashdata('success', 'Profile updated successfull.');
return redirect('user/user_profile');
} else {
$this->session->set_flashdata('error', 'Something went wrong. Please try again with valid format.');
redirect('user/user_profile');
}
}
}