Welcome Guest, Not a member yet? Register   Sign In
Solved: Noob: How can extend a helper?
#1

[eluser]Unknown[/eluser]
Hi all, i create a function for translate the english date to spanish. its work, but i wan to put it in to a helper for future use.
I read the manual, and i create a file system/helpers/MY_date_helper.php

This is the MY_date_helper.php file
Code:
<?php
function Fecha_Actual(){
    $this->load->helper('date'); /*I dont know how to use the mdate function into the date_helper*/
    $datestring = "%l %d %F %Y ";
    $time = time();
    $fecha = mdate($datestring, $time);
    $fecha = split( " ", $fecha);
    switch($fecha[0]){
         case "Monday":    $dia_esp = "Lunes";    break;
         case "Tuesday":   $dia_esp = "Miartes";  break;
         case "Wednesday": $dia_esp = "Miercoles";break;
         case "Thursday":  $dia_esp = "Jueves";  break;
         case "Fryday":    $dia_esp = "Viernes"; break;
         case "Saturday":  $dia_esp = "Sabado";  break;
         case "Sunday":    $dia_esp = "Domingo";    break;            
    }
    switch($fecha[2]){
        case "January":  $mes_esp = "Enero"; break;
        case "February": $mes_esp = "Febrero"; break;
        case "March":      $mes_esp = "Marzo"; break;
        case "April":    $mes_esp = "Abril"; break;
        case "May":      $mes_esp = "Mayo"; break;
        case "Juny":     $mes_esp = "Junio"; break;
        case "July":     $mes_esp = "Julio"; break;
        case "August":   $mes_esp = "Agosto"; break;
        case "September":$mes_esp = "Septiembre"; break;
        case "October":  $mes_esp = "Octubre"; break;
        case "November": $mes_esp = "Noviembre"; break;
        case "December": $mes_esp = "Diciembre"; break;
}
$fecha_actual = $dia_esp.", ".$fecha[1]." ".$mes_esp." ".$fecha[3];
return $fecha_actual;
}
?>

This is the code from the view where i wanna use the function
Code:
<?=$this->load->helper('MY_date');?>
  <div class="date">&lt;?=Fecha_Actual();?&gt;</div>

the error message
Fatal error: Using $this when not in object context in C:\wamp\www\proyectos\working\system\helpers\MY_date_helper.php on line 3

What iam doing wrong?
very txs in advance
#2

[eluser]Unknown[/eluser]
cuz MY_date_helper.php "extends" date_helper.php i dont need put
$this->load->helper('date');
in the code, just "use" the function
and another thing..
MY_date_helper.php must be located in system/application/helpers

and work now
bb




Theme © iAndrew 2016 - Forum software by © MyBB