How to removed url index.php in codeigniter ?
My output display :- http://localhost/shukla/index.php/home/about
And i tried to get result display:- http://localhost/shukla/home/about
http://localhost/:server_name/shukla/:folder_name/index.php/home/about/:about_page
I create a CodeIgniter, controller file--> Home.php
class Home extends CI_Controller {
public function index()
{
$this->load->view('template/header');
$this->load->view('home');
$this->load->view('template/footer');
}
public function about()
{
$this->load->view('template/header');
$this->load->view('about');
$this->load->view('template/footer');
}
public function contact()
{
$this->load->view('template/header');
$this->load->view('contact');
$this->load->view('template/footer');
}
}
In view folder: home.php , about.php, contact.php
config.php set base_url $config['base_url'] = 'http://localhost/project/';
removed index.php : $config['index_page'] = '';
In config.php there is an option "index_page" make it blank.
path : project_folder->application->config->config.php
change
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
Related
I have MY_Controller Extends CI_Controller
I have A Controller Extends MY_Controller and B Controller Extends MY_Controller
When I set session set_userdata in MY_COntroller in can be access in A Controller and also B Controller
But when set session set_userdata in A_Controller it can't be access in MY_Controller and B Controller
But after set session in a controller and print all userdata, the session is exist but not exist in other controller (B & MY COntroller)
IVE set the autoload libraries and also the config
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 1800;
$config['sess_save_path'] = sys_get_temp_dir();
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
My COntroller extends CI CONtroller
function __construct()
{
parent::__construct();
$this->readPath();
$this->readApiConfig();
$this->load->library('session');
$this->load->library('user_agent');
}
Login Controller extends My Controller
function __Construct()
{
parent::__Construct();
$this->load->library('encrypt');
$this->load->library('form_validation');
$this->load->helper('captcha');
$this->load->library('session');
$this->load->helper('cookie');
date_default_timezone_set("Asia/Bangkok");
}
function login(){
$email = array(
'usr_email' => $this->input->post("email")
);
$this->session->set_userdata('logged_in', $email);
redirect('landing');
}
Landing Controller extends My COntroller
function __construct()
{
parent::__construct();
$this->load->library('encrypt');
$this->load->library('session');
}
function index() {
//$prod = $this->getExistingAccount();
print_r($this->session->userdata('logged_in'));die();
}
AND ALSO I TRY to ses sess_save_path to APPPATH."CI_SESSION";
and add folder inside application folder name CI_SESSION and set the permission to 0700 but show white blank page
Web url : 192.xxx.x.x : port
My controller code is :
class Tconfig extends CI_Controller {
public $config;
public function __construct($schoolId = 1) {
parent::__construct();
$this->load->database();
$this->load->model('Tconfig_model');
$this->config = $this->Tconfig_model->load_config($schoolId);
}
public function config() {
$data['config'] = $this->config;
$this->load->view('templates/user_header', $data);
$this->load->view('templates/user_menu', $data);
// printf("%s", base_url());
//$this->load->view('config', $data);
//$this->load_view('templates/user_footer', $data);
}
}
I have autoloaded url_helper
At this point, I am just trying to load a HTML file which includes a call to base_url()
The exact line where this function is called is :
<link href=<?php echo base_url();?>"assets/bootstrap337/css/bootstrap.min.css" rel="stylesheet">
When I run this code through a debugger, I get this
What I cannot figure out is why I get a call to an undefined method stdClass::base_url() in url_helper.php
I am pretty sure that it's something very obvious, but it's been a long day .. TIA!
You have to load url helper in application->Config->autoload.php file
Like this:-
$autoload['helper'] = array('url');
OR
Add this in construct function in controller
$this->load->helper('url');
The problem is - you overwrite the CI intern Variable config with your own - you can avoid this by renaming your variable
something like the following should work
class Tconfig extends CI_Controller
{
public $tcConfig;
public function __construct($schoolId = 1)
{
parent::__construct();
$this->load->database();
$this->load->model('Tconfig_model');
$this->tcConfig = $this->Tconfig_model->load_config($schoolId);
}
public function config()
{
$data['config'] = $this->tcConfig;
$this->load->view('templates/user_header', $data);
$this->load->view('templates/user_menu', $data);
}
}
use this in your header file.
<script>
var base_url = '<?php echo base_url(); ?>';
</script>
check whether you defined your base url in your config.php file. If not, define it like-
$config['base_url'] = 'your-base-url';
in your config.php file in application/config folder.
I was uploading my code based on CI to a live website and it keeps getting error 404.
The web structure is like this :
web
-Application
-Assets
-Cache
-..so on
index.php
Here's my Application/Config/Routes.php file:
$route['default_controller'] = 'H';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
This is my H controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class H extends CI_Controller {
function __construct(){
parent::__construct();
if(empty($this->session->userdata("userData")['id'])) redirect('/login');
}
public function index()
{
$data = array();
if(isset($_GET['guid'])){
$data['post'] = getListPost($_GET['guid']);
}else{
$data['post'] = getStickyPost();
}
$this->load->view('partials/header');
$this->load->view('home',$data);
$this->load->view('partials/sidebar-home');
$this->load->view('partials/footer');
}
public function materi()
{
$this->load->view('partials/header');
$this->load->view('management/post/lists');
$this->load->view('partials/footer');
}
}
And this is my Login Controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function index($slug="")
{
if(isset($_POST['username'])){
$cek = $this->checkLogin($_POST['username'], $_POST['password']);
if($cek){
$newdata = array("userData"=>array(
'name' => $cek[0]['nama'],
'id' => $cek[0]['id'],
'nip' => $cek[0]['nip'],
'jabatan' => $cek[0]['jabatan'],
'unit_kerja' => $cek[0]['unit_kerja'],
'foto' => $cek[0]['foto'],
'hak_akses' => ($cek[0]['hak_akses_knowledge_management']=="")?"pengguna":$cek[0]['hak_akses_knowledge_management'],
'unit_kerja_atasan' => $cek[0]['unit_kerja_atasan'],
'email' => $_POST['username'],
'logged_in' => TRUE));
$this->session->set_userdata($newdata);
redirect('/');
}else{
$this->session->set_flashdata('login_status','false');
redirect('/login');
}
}
// $this->load->view('partials/header');
// $this->load->view('partials/login');
// $this->load->view('partials/footer');
$this->load->view('partials/single_login');
}
public function logout(){
$this->session->sess_destroy();
redirect('/');
}
public function newlogin(){
$this->load->view('partials/single_login');
}
function checkLogin($email,$password){
$this->db->where("nip",$email);
$this->db->where("password",$password);
$query = $this->db->get("data_pegawai");
return $query->result_array();
}
}
When I change the routes to default it works, somehow when i return to 'H' it keeps getting error 404.
This is the structure of views folder :
management
infografis
post
ebook
partials
header.php
single_login.php
footer.php
sidebar-home.php
login.php
category
infografis.php
ebook.php
errors
home.php
post.php
welcome_message.php
Routes are expected to be lowecase, even if Controller file names and class names begin with an uppercase character.
So, H.php, class H extends CI_Controller are correctly capitalized. However, $route['default_controller'] should be assigned a lowercase value.
Try using
$route['default_controller'] = 'h'; instead of 'H' and you should be up and running
I cant access to my login controller which is located in the sub directory login.
it is working perfectly in my local server.
in my default controller I did this
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function index()
{
redirect("login");
}
And in my routes.php
$route['login'] = 'login/log';
Can anyone help me out please?
Try this:
IN YOU CONFIG.PHP
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
I am using HMVC with CodeIgniter.
I have this in my testmodule controller:
public function index()
{
$this->view_data['main_content'] = 'frontpage';
$this->load->view('template', $this->view_data);
}
And this in my view template.php of that controller that is loaded by this controller:
<?php
$this->load->view('includes/header');
$this->load->view($main_content);
$this->load->view('includes/footer');
?>
but, when I var_dump($main_content) in the view and die() it shows null instead of frontpage
How, come? I don't get it at all.
If you want to use $this->view_data you have to declare $view_data as a property first (at the top of your controller):
class TestModule extends CI_Controller
{
public $view_data = array();
public function index()
{
// Now you can use $this->view_data in this function:
$this->view_data['main_content'] = 'frontpage';
$this->load->view('template', $this->view_data);
}
}