$_POST in phpbb using data json

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
DevMakoto
Registered User
Posts: 65
Joined: Tue Jun 23, 2015 3:38 pm
Name: Carlos Mayorga
Contact:

$_POST in phpbb using data json

Post by DevMakoto » Sat Mar 26, 2016 1:47 am

mi ajax

Code: Select all

$.ajax({
				type: "POST",
				url: "{AJAX_GENERAR_TABLA}",
				data: { horarios: JSON.stringify(objHorarios)},
				dataType:'html',
				success: function (result) {
					$("#horario").html(result).show();
			   }
			});
my objHorarios

Code: Select all

{
  "BFI22": [
    {
      "profesor": null,
      "data": [
        {
          "dia": "2",
          "aula": "131210",
          "ini": "08:00",
          "fin": "08:50",
          "prof": null
        },
        {
          "dia": "2",
          "aula": "133215",
          "ini": "08:50",
          "fin": "10:30",
          "prof": null
        },
        {
          "dia": "1",
          "aula": "133215",
          "ini": "08:00",
          "fin": "08:50",
          "prof": null
        }
      ],
      "turno": "01s",
      "tipo": "Teo",
      "curso": "FÍSICA I",
      "codigo": "BFI22",
      "color": {
        "nombre": "Azul oscuro medio",
        "codigo": "azul-oscuro-medio",
        "valor": "#004b8c"
      }
    },
    {
      "profesor": null,
      "data": [
        {
          "dia": "1",
          "aula": "131210",
          "ini": "08:50",
          "fin": "10:30",
          "prof": null
        }
      ],
      "turno": "90G",
      "tipo": "Lab",
      "curso": "FÍSICA I",
      "color": {
        "nombre": "Azul oscuro medio",
        "codigo": "azul-oscuro-medio",
        "valor": "#004b8c"
      },
      "codigo": "BFI22"
    }
  ],
  "BMA21": [
    {
      "profesor": null,
      "data": [
        {
          "dia": "4",
          "aula": "131210",
          "ini": "10:30",
          "fin": "13:00",
          "prof": null
        },
        {
          "dia": "3",
          "aula": "131210",
          "ini": "08:30",
          "fin": "10:30",
          "prof": null
        }
      ],
      "turno": "01s",
      "tipo": "Teo",
      "curso": "MATEMÁTICA II",
      "codigo": "BMA21",
      "color": {
        "nombre": "Azul oscuro medio",
        "codigo": "azul-oscuro-medio",
        "valor": "#004b8c"
      }
    }
  ]
}
in my controller

Code: Select all

$horarios = $this->request->variable('horarios', '', false,\phpbb\request\request_interface::POST);
		$data = json_decode($horarios);
		foreach($data as $key => $value) (this error)
		....
		...
		...
		
error return

Code: Select all

[phpBB Debug] PHP Warning: in file [ROOT]/ext/makoto/school/controller/controller_main.php on line 234: Invalid argument supplied for foreach()

Senky
Extension Customisations
Extension Customisations
Posts: 2082
Joined: Thu Apr 30, 2009 8:49 pm
Name: Jakub
Contact:

Re: $_POST in phpbb using data json

Post by Senky » Sat Mar 26, 2016 9:34 am

You need to cast your data object to array:

Code: Select all

$data = json_decode($horarios, true);

User avatar
DevMakoto
Registered User
Posts: 65
Joined: Tue Jun 23, 2015 3:38 pm
Name: Carlos Mayorga
Contact:

Re: $_POST in phpbb using data json

Post by DevMakoto » Sun Mar 27, 2016 3:03 pm

use htmlspecialchars_decode

Code: Select all

json_decode(htmlspecialchars_decode($horarios));

Post Reply

Return to “Extension Writers Discussion”