$route['default_controller'] = "index";
$route['404_override'] = '';
$route['(:any)'] = 'index/$1';
$route['admin'] = "admin/index";
$route['admin/add_category'] = "admin/index/add_category";
Works :
$route['admin/edit_category/2'] = "admin/index/edit_category/2";
Not working :
$route['admin/edit_category/(:any)'] = "admin/index/edit_category/$1";
Try to put Your rule before route which catches everything
$route['admin'] = "admin/index"; // no params at first
$route['admin/add_category'] = "admin/index/add_category"; // extend first rule
$route['admin/edit_category/(:any)'] = "admin/index/edit_category/$1"; // and one more
$route['default_controller'] = "index"; // default settings
$route['404_override'] = '';
$route['(:any)'] = 'index/$1'; // ok, now we can brake MVC pattern, but should we?
for example one of my route-files (works for sure):
$route['project-admin/login'] = "project-cms/user/index";
$route['project-admin/recovery'] = "project-cms/user/recovery";
$route['project-admin'] = "project-cms/admin/index";
$route['project-admin/(:any)'] = "project-cms/admin/$1";
$route['project-admin/(:any)/(:any)'] = "project-cms/admin/$1/$2";
Related
I set a session in a class from libraries. Then I tried to get the value of this session in another class from libraries. The value is empty.
I took a look in CodeIgniter Library to find out what the problem could be and at the some similar topics from StackOverflow but I don't see anything wrong from my end. maybe I am missing something. Please help.
// IN THIS CLASS I SET THE SESSION 'fr_phone'
class Form_submit_fr {
var $CI;
protected $fr_id;
protected $fr_data = array();
public function __construct() {
$this->CI =& get_instance();
if (strpos($this->CI->uri->segment(1),'frid') !== false){
$this->fr_id = (int)str_replace('frid','',$this->CI->uri->segment(1));
$this->fr_data = $this->get_fr_data();
// add the phone to session
if (isset($this->fr_data->city_toll) && $this->fr_data->city_toll != '') {
$fr_phone = $this->fr_data->city_toll;
} else {
$fr_phone = $this->fr_data->city_phone;
}
// here the session is set
$this->CI->session->set_userdata('fr_phone', $fr_phone);
//the result is correct
echo $this->CI->session->userdata('fr_phone') . ' - fr_phone<br>';
}
}
....
}
// IN THIS CLASS I NEED TO GET THIS SESSION 'fr_phone'
class P_details {
protected $page_link;
protected $fr_data;
var $CI;
public function __construct(){
$this->CI =& get_instance();
if ($this->CI->uri->segment(2) == false && $this->CI->uri->segment(3) == false) {
$this->page_link = $this->uri->segment(1)."/";
} else if ($this->CI->uri->segment(1) != false && $this->CI->uri->segment(2) != false && $this->CI->uri->segment(3) == false) {
$this->page_link = $this->CI->uri->segment(1)."/".$this->CI->uri->segment(2)."/";
} else if ($this->CI->uri->segment(1) != false && $this->CI->uri->segment(2) != false && $this->CI->uri->segment(3) != false) {
$this->page_link = $this->CI->uri->segment(1)."/".$this->CI->uri->segment(2)."/";
$this->fr_data = $this->get_fr_data($this->CI->uri->segment(3));
}
$this->CI->load->model('getDetails_model');
}
public function get_p_id($type = '') {
$details_array = $this->CI->getDetails_model->all_details($this->page_link);
if (empty($details_array)) {
return FALSE;
}
else {
$data['fr_phone'] = '';
$data['detail'] = $details_array;
// get phone from session
// here the session is empty
echo $this->CI->session->userdata('fr_phone') . ' - fr_phone<br>';
if ($this->CI->session->userdata('fr_phone')) {
$data['fr_phone'] = $this->CI->session->userdata('fr_phone');
}
if ($this->fr_data != '') {
$data['fr_detail'] = $this->fr_data;
}
return $data;
}
}
...
}
this is my config file:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
this is my autoload file:
$autoload['libraries'] = array('database','session');
I have made the suggested changes in config file for $config['sess_save_path']. thanks a lot. I could see the files in the writable folder and the entries in database when I checked this way as well:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 43200;
$config['sess_save_path'] = APPPATH.'writable';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
Also I used database for session:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 43200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
In both cases the session works if I define a session in Controller in constructor or index function. I can get session in View files and in other Classes but if I set a session under a condition for a specific link then this session is always empty when I want to get it in a class from libraries folder or in view files:
//in controller
if (strpos($this->uri->segment(1),'frid') !== false){
...
$fr_phone = '111-222-3333';
$this->session->set_userdata('fr_phone', $fr_phone);
echo $this->session->userdata('fr_phone') // works
}
When I call this session in a Class from libraries folder, the session is empty: above example for class P_details. And there is no way to get a session that is set in a Class from libraries folder and to get it in Another Class from libraries folder. It is very strange and I cannot get it. Also I tried to get session in a different controller and no success.
i had similar issue with one project. After long try i fix the issue the following way
1) in config.php
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'writable absolute path';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
and created the folder named "writable absolute path" in the root
Hopes this will help
It is very strange but I removed the session from autoload:
$autoload['libraries'] = array('database');
I added session_start(); in controllers and I set the session in a common way:
$_SESSION['fr_phone'] = $fr_phone;
Then I was able to get this value in any files. Is this a bug?
I tried without session_start() by adding $this->load->library('session'); and it did not work.
Can anyone find an answer to this issue?
I am using CodeIgniter 3.0.2
Using XAMPP for running codeigniter getting blank screen everytime in localhost. Other codeigniter project working well
$db['default']['username'] = "";
$db['default']['password'] = "";
$db['default']['database'] = "";
// The following values can probably stay the same.
$db['default']['hostname'] = "";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$active_group = "default";
$active_record = TRUE;
A blank screen usually means you have missed a " ; " someplace. I would say check your syntax completely. The missing ; might be in your view, controller or in the model. Almost any syntax error can bring you a blank screen
When my maintenance mode is on.
I would like to be able to still view the home page when maintenance mode is on.
But only if the member session role_id = 1
Currently does not let me view the home page at all even though my session role_id == 1 keeps redirecting to maintenance page
Question: How can I make sure can view home page if maintenance mode is active but if session role id == '1'
public function maintenance_mode() {
$maintenance_mode = $this->is_maintenance();
if ($maintenance_mode) {
if ($this->session->userdata('role_id') == '1') {
return true;
} else {
$route = $this->uri->segment(1) .'/'. $this->uri->segment(2);
$ignore = array('common/maintenance');
if (!in_array($route, $ignore)) {
redirect(base_url('common/maintenance'));
}
}
}
}
public function is_maintenance() {
$query = $this->db->where('item', 'maintenance_mode')->get('settings')->row('value');
return $query;
}
Solution
The code in my question was fine. I found the issue. it was creating the sessions twice one for www.example.co.nz and one for example.co.nz
I need to add cookie domain
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '.example.co.nz';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_sessions';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = APPPATH . 'cache/sessions/';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;
i have both admin panel and also one more front panel.....i have different controller for both and in my routes.php i made changes but because of that some links are not working
$route['default_controller'] = "site";
$route['404_override'] = '';
$route['contact'] = 'site/contact';
$route['events'] = 'site/events';
$route['terms'] = 'site/terms';
$route['privacy'] = 'site/privacy';
$route['newevent'] = 'site/add_event';
$route['(:any)'] = "site/$1";
//$route['(:any)'] = "backos/$1";
$route['listevents'] = 'backos/events';
$route['listwhatsapp'] = 'backos/whatsapp';
$route['add_artist'] = 'backos/add_artist';
$route['add_club'] = 'backos/add_club';
$route['index'] = 'backos/index';
$route['check'] = 'backos/check';
$route['add_event'] = 'backos/add_event';
$route['add_city'] = 'backos/add_city';
$route['add_locality'] = 'backos/add_locality';
//$route['(:any)'] = "backos/$1";
this is my routes.php file.
try this...
$route['default_controller'] = "site";
$route['404_override'] = '';
$route['contact'] = 'site/contact';
$route['events'] = 'site/events';
$route['terms'] = 'site/terms';
$route['privacy'] = 'site/privacy';
$route['newevent'] = 'site/add_event';
$route['listevents'] = 'backos/events';
$route['listwhatsapp'] = 'backos/whatsapp';
$route['add_artist'] = 'backos/add_artist';
$route['add_club'] = 'backos/add_club';
$route['index'] = 'backos/index';
$route['check'] = 'backos/check';
$route['add_event'] = 'backos/add_event';
$route['add_city'] = 'backos/add_city';
$route['add_locality'] = 'backos/add_locality';
// this is a catch all if you don't put it as
// the last one everything else below it wont work!
$route['(:any)'] = "site/$1";
I am working on codeigniter site.I have one single application this application is used by various user each user is having its own DB(Its own clients also).I need the way how to approach this cloud system.
As i have the single copy of application folder and only the difference in DB for each user.
I have tried by creating subdomain directory in codeigniter and writing index file and htaccess file so that i can access my original application.but i need the subdomain path in url and way how to connect to the database according to that subdomian url path.
htaccess file.
RewriteEngine On
RewriteRule /test/(.*) /$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
which way i should follow to complete this work.Please help
Thanks in advance.
Here's what we do:
In config/database.php, we define a set of different DB settings, which are picked based on domain. You can adjust/extend that easily.
if($_SERVER['SERVER_NAME'] == 'www.stagingserver.com'){
$active_group = "staging";
$db['staging']['hostname'] = "95.xxx.xxx.xxx";
} else {
$active_group = "default";
}
$db['default']['hostname'] = "localhost:8889";
$db['default']['username'] = "root";
$db['default']['password'] = "root";
$db['default']['database'] = "database";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$db['staging']['username'] = "movers_user";
$db['staging']['password'] = "staging_user";
$db['staging']['database'] = "staging_database";
$db['staging']['dbdriver'] = "mysql";
$db['staging']['dbprefix'] = "";
$db['staging']['pconnect'] = TRUE;
$db['staging']['db_debug'] = TRUE;
$db['staging']['cache_on'] = FALSE;
$db['staging']['cachedir'] = "";
$db['staging']['char_set'] = "utf8";
$db['staging']['dbcollat'] = "utf8_general_ci";
I have tried something like this.....
In my database.php file
$active_group = 'default';
$active_record = TRUE;
$uri = $_SERVER['REQUEST_URI'];
$pieces = explode('/', $uri);
if($pieces[1]==""){
$_SESSION['user_db_username']='**';
$_SESSION['user_db_pass']='**';
$_SESSION['user_db_name']='**';
}
else
{
$link = mysql_connect('**', '**', '**');
if($link){
$db_selected = mysql_select_db('**', $link);
if ($db_selected)
{
$query_arr= "SELECT * FROM ** where domain='".$pieces[1]."' ";
$queryResult_arr=mysql_query($query_arr,$link);
while($row=mysql_fetch_assoc($queryResult_arr))
{
$_SESSION['user_db_user']=$row['**'];
$_SESSION['user_db_pass']=$row['**'];
$_SESSION['user_db_name']=$row['**'];
}
}
}
}
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = $_SESSION['user_db_username'];
$db['default']['password'] = $_SESSION['user_db_pass'];
$db['default']['database'] = $_SESSION['user_db_name'];