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';
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
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'] = '';
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'm trying to setup CodeIgniter (v2.1.4) with Query Strings and having problems with passing variables. The pages work when the controller_trigger and function_trigger are passed:
example.org/?c=page&m=index
But when I try to pass a variable:
example.org/?c=page&m=view&id=1
The script throws 'Missing argument' and 'Undefined variable' errors.
In 'application/config/config.php' I've set:
$config['enable_query_strings'] = TRUE;
In 'application/config/routes.php' I have:
$route['default_controller'] = "page";
And my Controller looks like:
<?php
class Page extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('page_model');
}
public function index()
{
$data['title'] = 'Page Title';
$this->load->view('templates/header', $data);
$this->load->view('page/page_index', $data);
$this->load->view('templates/footer');
}
public function view($id)
{
$data['title'] = 'Id Page Title';
$data['page_item'] = $this->page_model->get_page($id);
$this->load->view('templates/header', $data);
$this->load->view('page/page_view', $data);
$this->load->view('templates/footer');
}
}
Does anyone know what I've missed?
Any help would be greatly appreciated
In your config.php change:
$config['allow_get_array'] = TRUE; #example.com?who=me&what=something&where=here
Write it like this
example.org?c=page&m=index
without "/"
I am using Tank_auth for user authentication in codeigniter. To check if any user is logged in or not, if he is then to get the username and id I need to use the following code in every functions of my controllers, which is very irritating.
// If any user is logged in get his/her userid or name
if ($this->tank_auth->is_logged_in()) {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
}
So , I was wondering if I could make life easier by putting the following code inside the function __construct() like following,
but its not working.
Could you please tell me how to get it work?
Thanks in Advance :)
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->library('tank_auth');
if ($this->tank_auth->is_logged_in()) {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
}
}
if you plan to use this array only inside this controller, you can use it like this:
//outside the functions define the $data as controller class property:
private $data = array();
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->library('tank_auth');
if ($this->tank_auth->is_logged_in()) {
$this->data['user_id'] = $this->tank_auth->get_user_id();
$this->data['username'] = $this->tank_auth->get_username();
}
}
//and then use it like
function index(){
$this->load->view("something.php",$this->data);
}