How to create log files using codeigniter - php

My project is going on using codeigniter.
I am new to codigniter and I want to bring log module into my project.
I want to capture all activities including errors into the log file.
Do i need to make changes in all page to store changes in log file.
where should i write function for this , whether in controller or library.
Is the log module feature exist in codeigniter?
can anyone give me the solution for this

Create library or helper and use Autoload. AFAIK codeigniter have no such default kinda library or helper, you need create your own or do research for external one.
EDIT :
My bad, try to find $config['log_threshold'] = 0; and $config['log_path'] = ''; in your config.php

Related

CodeIgniter + Ion Auth: Ion Auth config file is loaded twice

Explanation:
Using CodeIgniter v3.1.2 with Ion Auth 2
I separated the admin area and user area into 2 different applications to improve security.
I wanted to share config files between two apps so for application_admin/config/ion_auth.php I did this:
require_once(__DIR__.'/../../application_users/config/ion_auth.php');
The script stopped working and after some hours I realized the file is being loaded twice because when I use require instead of require_once everything work's fine.
Questions:
Shouldn't CodeIgniter check and prevent loading files that are already loaded twice? if yes then why is this happening, and if not is it okay if I just use require instead of require_once?
Is my approach the correct way of sharing config files and helpers between multiple applications in a single CI install?
Edit:
I put the require_once in the admin/config/ion_auth.php to include user/config/ion_auth.php so basically I'm putting the content of that config file in this config file "only when CodeIgniter itself loads this config file".
Also even if I put the normal ion_auth config file without any require/include etc, it is still loaded twice (I noticed by putting a simple echo 'loaded<br>'; in the end of config file.)
Shouldn't CodeIgniter check and prevent loading files that are already
loaded twice? if yes then why is this happening, and if not is it okay
By making direct call to require or require_once you are bypassing Codeigniter (CI) so it has no way of knowing what you have or have not included.
if I just use require instead of require_once? Is my approach the
correct way of sharing config files and helpers between multiple
applications in a single CI install?
Loading a config file in CI should be done using the Config class. If you dig into the source code for Ion Auth and look at __construct in Ion-auth_model.php you will find heavy use of the config class to read the config file and access various config items. It a good example of the "CI way" to handle configuration.

Codeigniter 3 dev Unable to load the requested class

I'm new in CI and now I'm trying to use CodeIgniter 3 to develop my site. I just only extract the framework and change only one think in config/autoload.php file:
$autoload['libraries'] = array('database','input');
when I run the site, an error occur:
Unable to load the requested class: Input
When I tried it with CI version 2.2.0 stable, every thing is OK, no errors
Could some one explain why and help me to solve it?
As of documentation input library is loaded by default.
This class (input) is initialized automatically by the system so there is no need to do it manually.
Autoloading documentation http://www.codeigniter.com/userguide3/general/autoloader.html
By default the library load from system/core folder in you CI. But the Input library is located on the core folder so you need to give relative path to the Input.php like this
$autoload['libraries'] = array('database','../core/input');

How to check Trace or log file in YII?

I Want to use log functionality from YII and i am new to YII.
Can anyone guide me where is file location of logging content? or tracing content?
If you are using default Yii main.php file then all the logs go to your protected/runtime/application.log file. It will include standard Yii logs as well as you own Yii::log() calls too.

CodeIgniter Modular Extensions & the i18n library

I have been using the CodeIgniter i18n library by Jérôme Jaglale (http://maestric.com/en/doc/php/codeigniter_i18n), which works great for my project.
But since I need to write separate modules, I recently added CodeIgniter Modular Extensions ( https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc ) and the navigation breaks.
How can I solve this issue please, I would love to use both the i18n library & Modular Extensions.
I think my application navigation fails to work because i18n library introduces adds a language segment in the site url, in my case my url is localhost/index.php/en/home and after adding Modular Extensions, my navigation/links stop working.
Thank you in advance.
Recently, I try to use HMVC with i18n and have similar problem. Below is my solution.
1.first you need to go to here HMVC select "Branches" to download HMVC extension, don't download the one on github it might not work.
2.Unzip HMVC extension inside the folder copy two files "MY_Loader.php" and "MY_Router.php" from core folder to Codeigniter's "application/core" after that copy "MX" folder from "third_party" to Codeigniter's "application/third_party". By this point your HMVC is installed, however it will not work because i18n cause the problem so if you run your website it might not display.
3.You need to get new version of i18n which support both HMVC and none HMVC, the old version of i18n seems not support HMVC. Go to here i18n download it and take time to read the description on github.
4.Before this step I suggest you to backup "application/core/MY_Config.php" and "application/core/MY_Lang.php" in case something goes wrong you can reverst back. Unzip i18n inside folder copy file "language.php" from config folder to Codeigniter's "application/config", copy two files "MY_Config.php" and "MY_Lang.php" from core folder to Codeigniter's "application/core", finally copy "MY_language_helper.php" from helpers folder to Codeigniter's "application/helpers". So far you have new i18n installed, but you need to configure it to make it work, otherwise you might get error message.
5.Open "application/core/MY_Config.php" and replace the line require_once APPPATH . "libraries/MX/Config.php"; to require_once APPPATH . "third_party/MX/Config.php"; then open "application/core/MY_Lang.php" replace the line require APPPATH . "libraries/MX/Lang.php"; to require APPPATH . "third_party/MX/Lang.php";. Why? because it point to the wrong directory, the MX folder is located in "third_party" not "libraries" in case you don't know, if you don't change it you might get error message.
6.To add new language(Not create language file) you need to open "application/config/language.php". You see at top the code block with comment says "Supported Languages" there already have English and Russian language configure for you just need to copy the template and change to the language you want, it's very easy. Be aware folder's name must exactly the same as folder in "application/language".
7.According to i18n github description you need to add these line
$route['^(en|de|fr|nl)/(.+)$'] = "$2";
$route['^(en|de|fr|nl)$'] = $route['default_controller'];
to the "application/config/routes.php". Be aware this line $route['^(en|de|fr|nl)/(.+)$'] = "$2"; in old i18n probably is $route['^(en|de|fr|nl)/(.+)$'] = "$1"; the difference is "$1" have to change to "$2", otherwise you will got problem.
8.To create language file is same as the method you did in old i18n. Now test your website with multi-language to make sure everything work fine.
9.Create your module. How? Create a folder name "modules" inside Codeigniter's application folder, inside modules folder you can start to create your module. That's say you want to create a module call foo, you just need to create a folder name it "foo" and then inside foo folder you can create three folders controllers, models and views. Create a php file with name foo with the code below
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Foo extends MX_Controller
{
public function index()
{
echo "<h1>class foo this is module test</h1>";
}
}
Enter url to run your module, if you see "class foo this is module test" then it work.
Remember module class must extends from MX_Controller.
If you still encounter any problem just ask.

bootstrap.php file in CodeIgniter PHP framework?

I am new in php. I am learning Code Igniter (a PHP framework). Can anybody let me know is there any bootstrap.php file in codeIgniter ? And if yes then what it does?
I googled but no luck for bootstrap.php file for CodeIgniter, however i got the bootstrap.php file for Zend and one other framework.
Many Thanks.
application/config
From the question, I'm assuming you would like to know where this file is to add something to it.
The bootstrap file in CakePHP is for additional application settings and setup logic - the equivalent file in Codigniter is probably the application/config/config.php file.
The bootstrap file in Zend contains a class used for initializing the whole application , which by default reads a config.ini file. Depending on specifically what it is you're looking for in "bootstrap.php file in CodeIgniter" - again, the application config files are the CI equivalent of this file's logic/purpose.
The CodeIgniter bootstrap file is the CodeIgniter.php located in system/core.

Categories