codeigniter define ENVIRONMENT for specific controller - codeigniter

codeigniter has in index.php define('ENVIRONMENT', 'production'); for whole website. I am makeing changes in specific controller so I would like to have setting define('ENVIRONMENT', 'development'); for this controller but leave 'production' for all other controllers.
Is it possible to achieve this?

This constant is set just for enabling disabling errors. The production ENVIRONMENT disables all errors. If you want to enable development for a specific controller, then just place the below code at top of that controller.
error_reporting(E_ALL);
OR
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
Also read
How do I enable error reporting in PHP?

Related

Codeigniter display blank page and no errors

When I access my application, browser display blank page like this :
There is no error
My application using codeigniter
Any help much appreciated
Cheers
Probably your environment is not displaying errors. This can be because your php.ini configuration or because the definition of the constant ENVIRONMENT in spsubagent/index.php.
If your php.ini are configured correctly, so you 'ENVIROMENT' constant must be defined with 'development' value to display errors, because the 'production' value must hide errors.
Bad practice:
You can force the exibition of the error defining the error_reporting(E_ALL); in the construct of your controller.
Check your .htaccess file or replace your htaccess file with new htaccess file for codeigniter.

multiple environments with codeigniter

I'm trying to understand the best course of action with using multiple environments, such as development, testing, production for my application with codeigniter.
As of right now I have one folder for my application. I'm seen places that talk about in the config file doing a folder for each of the environments and placing for example a copy of the database file in each of the environment folders.
Is this the best method of handling multiple environments? The reason I'm asking is because if I work on my dev subdomain I'd still have to reupload to the main root folder all the same files. Is this the best workflow?
So basically I have two sites.
dev.siteurl.com
siteurl.com
I'm trying to figure out the best option of handling this. Because I'm wondering if I'm going to just have to reupload all the files again to the main level so that it can handle the production server or is there an easier way.
Yes the way it works is under your /application/config folder you create an extra nested folder called development so that you have
/application/config/development/
Inside development you will place a copy of your database.php file and change your development database settings
/application/config/development/database.php
THEN you have to tell codeigniter which version you are on, so in your base root folder edit index.php:
/index.php
define('ENVIRONMENT', 'development');
When you want to use the /config/development/database.php you will change your environment to development, and when you want to use the production database you will change the environment to production
edit: also the CI TOC has a brief section explaining this: https://www.codeigniter.com/user_guide/general/environments.html
I'm defining envirement in index.php
do something like
if ($_SERVER['SERVER_NAME']=='siteurl.com')
define('ENVIRONMENT', 'production');
else if ($_SERVER['SERVER_NAME']=='test.siteurl.com')
define('ENVIRONMENT', 'testing');
else
define('ENVIRONMENT', 'development');
and use config sections according to ENVIRONMENT variable
I know this is an old thread, but I am working on a Codeigniter project now and was looking for a good way to maintain two environments without having to maintain two codebases at two different urls. In case anyone else is looking for a similar answer, here's a possible solution that allows you to maintain one codebase.
For my current project, I have siteurl.com and siteurl.com/sandbox.
siteurl.com/index.php
define('ENVIRONMENT', 'production');
$system_path = '../system';
$application_folder = '../application';
siteurl.com/sandbox/index.php
define('ENVIRONMENT', 'development');
$system_path = '../../system';
$application_folder = '../../application';

Codeigniter Session Outside the application folder

Is it possible to get session outside codeigniter application folder?
It is possible, but not without some work. You can see the details of someone else's problem and their solution in the CodeIgniter forum.
Basically you need take the cookie that CodeIgniter uses to handle it's sessions and unserialize it:
$sess = unserialize($_COOKIE['ci_session']);
You may need to also change settings in your application so that cookies are set for the entire domain, not just for the folder that CodeIgniter sits in.
Its a trick but do work. Place this little naughty code just before login redirect. And now you can use ci_session with php native session too ,have fun !
<?php
session_start();
echo $_SESSION['ci_session'] = $this->session->userdata['ci_session'];
?>

Codeigniter in shared ssl

I am not able to get codeigniter to work on my shared ssl url.
for example, on
https://nimrod.eukhosting.net/~nadavwei/myatar.co.cc/aaa
i get a 404 error
aaa is just a demo controller that should echo test
only the homepage - with no controller in the url - works
https://nimrod.eukhosting.net/~nadavwei/myatar.co.cc/
btw, i am using .htaccess
thanks
It looks like your provider is disabling .htaccess for the https server.
I am able to see your website here: https://nimrod.eukhosting.net/~nadavwei/myatar.co.cc/index.php/categories/26
But it won't work here: https://nimrod.eukhosting.net/~nadavwei/myatar.co.cc/categories/26
My guess is that their setup allows or disallows .htaccess based on the virtual domain, and since you are not using your virtual domain, it is being disabled. You should contact your hosting provider and see if they know or can provide more information.
You can also double check your .htaccess file, in case there is something about it specifying the virtual domain.
Also, as an FYI, you are going to have to modify your CodeIgniter configuration so that it dynamically the full path and turns on or off the index.php part of your URL based on whether or not the user is arriving via HTTPS:
$is_https = !empty($_SERVER['HTTPS']);
$config['base_url'] = $is_https ?
'https://nimrod.eukhosting.net/~nadavwei/myatar.co.cc/' :
'http://myatar.co.cc/';
$config['index_page'] = $is_https ? 'index.php' : '';
This should toggle the modes as necessary.

Drupal 6: Change redirect of Node Edit form with Ajax Module installed

Is it possible to do this? I am using hook_form_alter to change the redirect of $form_state and #redirect of $form, as well as changing it using the ajax_alter hook the module uses. Even changing it in both these places it somehow ends up set to redirect to the node being edited.
Any ideas?
If you are using this AJAX module, it has an useful submodule called Disable Redirection that comes with the module. Enable it and remember to enable the checkboxes from the settings.

Resources