[eluser]ayukawaa[/eluser]
[quote author="Binod Kumar Luitel" date="1369797443"]Here is a little of my contribution to Codeigniter:
Code:
...
function __construct(){
log_message('debug','Log_Maintenance : class loaded');
parent::__construct($rules);
$this->CI =& get_instance();
// check whether the config is a numeric number before assigning
if(isset($this->CI->config->item('logs_files_for')))
$this->logs_files_for = (int) (is_numeric($this->CI->config->item('logs_files_for')) ? $this->CI->config->item('logs_files_for') : 15);
// delete the old log files
$this->delete_logs();
}
...
[/quote]
Good work, I'm using it now, just one thing that I have changed for myself:
In the
function __construct() because you have the default setting (
private $logs_files_for = 15;) no need for more, just a cast it with a string '0'
before to get rid of nulls, NEGATIVE, etc... and done...
"
-3" IS
is_numeric AND
int
use this
Code:
$new_logs_files_for = (int)('0'.$this->CI->config->item('logs_files_for'));
$this->logs_files_for = $new_logs_files_for>0 ? $new_logs_files_for : $this->logs_files_for;
or this
Code:
$new_logs_files_for = (int)('0'.$this->CI->config->item('logs_files_for'));
if($new_logs_files_for>0)
{
$this->logs_files_for = $new_logs_files_for;
}
This way you don't have to check if config var exists, numeric, int, etc... and only changes value IF it is greater than 0.