Maybe you guys can help me I am trying to do this:
public function index()
{
$r = array();
//some code
echo json_encode($this->utf8ize($r));
}
public function utf8ize($d) {
//some code
return $d;
}
But I get the "Call to undefined function utf8ize()" error
Why?
Edit 1: The complete code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Solicitud extends MX_Controller {
public function __construct()
{
/*
parent::__construct();
if(!$this->input->is_ajax_request())
{
show_404();
exit();
}
else
{
*/
$this->load->model('Solicitud_model', 'Model');
//}
}
public function index()
{
$bandera = $this->input->post('bandera');
$r = array();
if ($bandera == 1){
$result = $this->Model->getConsulta($this->session->session_facultad_apps);
$r = array("data" => $result,
"success" => true,
"bandera" => $bandera);
}else if($bandera == 2)
{
$result = $this->Model->get($this->session->session_facultad_apps);
$r = array("data" => $result,
"success" => true,
"bandera" => $bandera);
}else if ($bandera == 3){
$result = $this->Model->getAsigna($this->session->session_facultad_apps);
$r = array("data" => $result,
"success" => true,
"bandera" => $bandera);
}
echo json_encode(utf8ize($r));
}
public function utf8ize($d) {
if (is_array($d)) {
foreach ($d as $k => $v) {
$d[$k] = utf8ize($v);
}
} else if (is_string ($d)) {
$d = iconv('UTF-8', 'ISO-8859-1', $d);
return utf8_encode($d);
}
return $d;
}
this
is used to reference the current instance of an object. In your case, you missed the reference to this for the recursive call.
Simple solution - also add $this->
to the inner utf8ize
call
echo json_encode($this->utf8ize($r));
...
public function utf8ize($d) {
if (is_array($d)) {
foreach ($d as $k => $v) {
$d[$k] = $this->utf8ize($v);
}
} else if (is_string ($d)) {
$d = iconv('UTF-8', 'ISO-8859-1', $d);
return utf8_encode($d);
}
return $d;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments