Дело такое: Есть вебстраничка, содержащая формат данных json, большая вложенность массивов (3-4 уровня), их нужно decode в массив и разбить по полям в табличку (html табличку, не бд!).
Что то вроде Участок|Врач|Кабинет|Дни приема (и тут пн: 10-18, вт: 11-23, ср: 10-12).
ИЗ-за большой вложенности не могу добраться до нужного элемента. Поэтому разбил jsonовский код на мелкие кусочки, занес их в переменные, каждую преобразовал, а потом ручками каждую запись вставляю в табличку. понимаю, что пишу говнокод. Можно ведь как то циклом, да в несколько строк.
Подскажите, пожалуйста.
Код контроллера:
Код: Выделить всё
class LpuController extends Controller
{
public function actionIndex()
{
$models = Lpu::model()->findAll(array('order'=>'name ASC'));
$this->render('index', array('models'=>$models));
}
public function actionView($id)
{
$json1='{"district":"","fio":"Андреева Любовь Александровна","room":"6","speciality":"Физиотерапевт","schedule":[{"date":"21.01.2014","times":[{"from":"08:00","to":"16:00"}]},{"date":"22.01.2014","times":[{"from":"13:00","to":"16:00"},{"from":"08:00","to":"12:00"}]},{"date":"23.01.2014","times":[{"from":"08:00","to":"16:00"}]},{"date":"24.01.2014","times":[{"from":"08:00","to":"16:00"}]},{"date":"27.01.2014","times":[{"from":"08:00","to":"16:00"}]}]}';
$json2='{"district":"","fio":"Батракова Ирина Петровна","room":"118","speciality":"Рентгенолог ","schedule":[{"date":"21.01.2014","times":[{"from":"10:00","to":"12:00"},{"from":"13:00","to":"14:00"}]},{"date":"22.01.2014","times":[{"from":"13:00","to":"14:00"},{"from":"10:00","to":"12:00"}]},{"date":"23.01.2014","times":[{"from":"10:00","to":"12:00"},{"from":"13:00","to":"14:00"}]},{"date":"24.01.2014","times":[{"from":"10:00","to":"12:00"},{"from":"13:00","to":"14:00"}]},{"date":"27.01.2014","times":[{"from":"13:00","to":"14:00"},{"from":"10:00","to":"12:00"}]}]}';
$json3='{"district":"","fio":"Башкиров Леонид Владимирович","room":"205","speciality":"Узи","schedule":[{"date":"24.01.2014","times":[{"from":"14:30","to":"18:00"}]}]}';
$json4='{"district":"","fio":"Берендеева Елена Павловна","room":"208, Ревматолог","speciality":"Ревматолог","schedule":[{"date":"21.01.2014","times":[{"from":"14:00","to":"20:00"}]},{"date":"23.01.2014","times":[{"from":"16:00","to":"20:00"}]}]}';
$json5='{"district":"","fio":"Борисов Алексей Сергеевич","room":"46","speciality":"Травматолог-ортопед","schedule":[{"date":"21.01.2014","times":[{"from":"09:00","to":"12:00"}]},{"date":"22.01.2014","times":[{"from":"09:00","to":"12:00"}]},{"date":"23.01.2014","times":[{"from":"09:00","to":"12:00"}]},{"date":"24.01.2014","times":[{"from":"09:00","to":"12:00"}]},{"date":"27.01.2014","times":[{"from":"09:00","to":"12:00"}]}]}';
$json6='{"district":"","fio":"Буйкина Алла Викторовна","room":"205","speciality":"Узи","schedule":[{"date":"21.01.2014","times":[{"from":"13:20","to":"16:30"}]},{"date":"22.01.2014","times":[{"from":"08:00","to":"11:00"}]},{"date":"23.01.2014","times":[{"from":"13:20","to":"16:30"}]},{"date":"24.01.2014","times":[{"from":"08:00","to":"11:30"}]},{"date":"27.01.2014","times":[{"from":"08:00","to":"11:30"}]}]}';
$json7='{"district":"","fio":"Буфалова Елена Ивановна","room":"10","speciality":"Уролог","schedule":[{"date":"21.01.2014","times":[{"from":"08:00","to":"14:30"}]},{"date":"22.01.2014","times":[{"from":"13:00","to":"14:30"},{"from":"08:00","to":"12:00"}]},{"date":"23.01.2014","times":[{"from":"08:00","to":"14:30"}]},{"date":"24.01.2014","times":[{"from":"08:00","to":"14:30"}]},{"date":"27.01.2014","times":[{"from":"13:00","to":"19:00"}]}]}';
$json8='{"district":"26уч.","fio":"Голубенко Татьяна Валентиновна","room":"9","speciality":"Терапевт","schedule":[{"date":"21.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"22.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"23.01.2014","times":[{"from":"16:00","to":"20:00"}]},{"date":"24.01.2014","times":[{"from":"12:00","to":"16:00"}]},{"date":"27.01.2014","times":[{"from":"08:00","to":"12:00"}]}]}';
$json9='{"district":"3уч.","fio":"Гомбоева Эржэма Найдановна","room":"216","speciality":"Терапевт","schedule":[{"date":"21.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"22.01.2014","times":[{"from":"12:00","to":"16:00"}]},{"date":"23.01.2014","times":[{"from":"12:00","to":"16:00"}]},{"date":"24.01.2014","times":[{"from":"16:00","to":"20:00"}]},{"date":"27.01.2014","times":[{"from":"12:00","to":"16:00"}]}]}';
$json10='{"district":"","fio":"Егорова Наталья Валентиновна","room":"35","speciality":"Рентгенолог ","schedule":[{"date":"21.01.2014","times":[{"from":"15:00","to":"18:00"}]},{"date":"22.01.2014","times":[{"from":"15:00","to":"18:00"}]},{"date":"23.01.2014","times":[{"from":"15:00","to":"18:00"}]},{"date":"24.01.2014","times":[{"from":"15:00","to":"18:00"}]},{"date":"27.01.2014","times":[{"from":"15:00","to":"18:00"}]}]}';
$json11='{"district":"","fio":"Зейля Марина Юрьевна","room":"23","speciality":"Узи","schedule":[{"date":"21.01.2014","times":[{"from":"15:30","to":"17:50"},{"from":"12:15","to":"15:00"}]},{"date":"23.01.2014","times":[{"from":"09:00","to":"11:45"},{"from":"12:15","to":"14:55"}]},{"date":"24.01.2014","times":[{"from":"08:30","to":"11:45"},{"from":"12:15","to":"14:30"}]},{"date":"27.01.2014","times":[{"from":"08:30","to":"11:45"},{"from":"12:15","to":"14:30"}]}]}';
$json12='{"district":"","fio":"Зильберман Евгения Васильевна","room":"39","speciality":"Терапевт","schedule":[{"date":"21.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"22.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"23.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"24.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"27.01.2014","times":[{"from":"08:00","to":"12:00"}]}]}';
$json13='{"district":"","fio":"Зуев Алексей Станиславович","room":"46","speciality":"Хирург","schedule":[{"date":"21.01.2014","times":[{"from":"16:00","to":"20:00"}]}]}';
$json14='{"district":"22уч.","fio":"Казанцева Тамара Тимофеевна","room":"9","speciality":"Терапевт","schedule":[{"date":"21.01.2014","times":[{"from":"16:00","to":"20:00"}]},{"date":"22.01.2014","times":[{"from":"13:00","to":"16:00"}]},{"date":"23.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"24.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"27.01.2014","times":[{"from":"12:00","to":"16:00"}]}]}';
$json15='{"district":"","fio":"Кайгородова Ирина Юрьевна","room":"25","speciality":"Офтальмолог","schedule":[{"date":"24.01.2014","times":[{"from":"08:00","to":"14:30"}]}]}';
$json16='{"district":"","fio":"Кайгородова Ирина Юрьевна","room":"310","speciality":"Офтальмолог","schedule":[{"date":"21.01.2014","times":[{"from":"11:30","to":"18:00"}]},{"date":"22.01.2014","times":[{"from":"08:00","to":"14:15"}]},{"date":"23.01.2014","times":[{"from":"08:00","to":"14:15"}]},{"date":"27.01.2014","times":[{"from":"08:00","to":"14:15"}]}]}';
$json17='{"district":"6уч.","fio":"Камалетдинова Марина Николаевна","room":"218","speciality":"Терапевт","schedule":[{"date":"21.01.2014","times":[{"from":"16:00","to":"20:00"}]},{"date":"22.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"23.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"24.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"27.01.2014","times":[{"from":"12:00","to":"16:00"}]}]}';
$json18='{"district":"","fio":"Карзилова Галина Шамильевна","room":"322","speciality":"Невролог","schedule":[{"date":"21.01.2014","times":[{"from":"08:00","to":"08:45"},{"from":"09:30","to":"14:00"}]},{"date":"22.01.2014","times":[{"from":"13:00","to":"19:00"}]},{"date":"23.01.2014","times":[{"from":"09:30","to":"14:00"},{"from":"08:00","to":"08:45"}]},{"date":"24.01.2014","times":[{"from":"09:30","to":"14:00"},{"from":"08:00","to":"08:45"}]},{"date":"27.01.2014","times":[{"from":"12:00","to":"18:00"}]}]}';
$json19='{"district":"21уч.","fio":"Каширина Татьяна Борисовна","room":"44","speciality":"Терапевт","schedule":[{"date":"21.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"22.01.2014","times":[{"from":"16:00","to":"20:00"}]},{"date":"23.01.2014","times":[{"from":"12:00","to":"16:00"}]},{"date":"24.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"27.01.2014","times":[{"from":"12:00","to":"16:00"}]}]}';
$json20='{"district":"28уч.","fio":"Ким Кристина Львовна","room":"14","speciality":"Терапевт","schedule":[{"date":"21.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"22.01.2014","times":[{"from":"15:00","to":"19:00"}]},{"date":"23.01.2014","times":[{"from":"16:00","to":"20:00"}]},{"date":"24.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"27.01.2014","times":[{"from":"08:00","to":"12:00"}]}]}';
$json21='{"district":"","fio":"Коротких Светлана Геннадьевна","room":"13","speciality":"Невролог","schedule":[{"date":"21.01.2014","times":[{"from":"14:00","to":"18:00"}]},{"date":"22.01.2014","times":[{"from":"14:00","to":"18:00"}]},{"date":"23.01.2014","times":[{"from":"14:00","to":"18:00"}]},{"date":"24.01.2014","times":[{"from":"16:00","to":"18:00"}]},{"date":"27.01.2014","times":[{"from":"09:00","to":"13:00"}]}]}';
$json22='{"district":"25уч.","fio":"Кошкина Клавдия Никифоровна","room":"31","speciality":"Терапевт","schedule":[{"date":"21.01.2014","times":[{"from":"12:00","to":"16:00"}]},{"date":"22.01.2014","times":[{"from":"08:00","to":"12:00"}]},{"date":"23.01.2014","times":[{"from":"12:00","to":"16:00"}]},{"date":"24.01.2014","times":[{"from":"16:00","to":"20:00"}]},{"date":"27.01.2014","times":[{"from":"08:00","to":"12:00"}]}]}';
$json23='{"district":"","fio":"Ли Станислав Радиевич","room":"46","speciality":"Хирург","schedule":[{"date":"22.01.2014","times":[{"from":"16:00","to":"20:00"}]},{"date":"24.01.2014","times":[{"from":"16:00","to":"20:00"}]},{"date":"27.01.2014","times":[{"from":"16:00","to":"20:00"}]}]}';
$json23='{"days":{"21.01.2014":"Вт","22.01.2014":"Ср","23.01.2014":"Чт","24.01.2014":"Пт","27.01.2014":"Пн"}';
$decode1=CJSON::decode($json1);
$decode2=CJSON::decode($json2);
$decode3=CJSON::decode($json3);
$decode4=CJSON::decode($json4);
$decode5=CJSON::decode($json5);
$decode6=CJSON::decode($json6);
$decode7=CJSON::decode($json7);
$decode8=CJSON::decode($json8);
$decode9=CJSON::decode($json9);
$decode10=CJSON::decode($json10);
$decode11=CJSON::decode($json11);
$decode12=CJSON::decode($json12);
$decode13=CJSON::decode($json13);
$decode14=CJSON::decode($json14);
$decode15=CJSON::decode($json15);
$decode16=CJSON::decode($json16);
$decode17=CJSON::decode($json17);
$decode18=CJSON::decode($json18);
$decode19=CJSON::decode($json19);
$decode20=CJSON::decode($json20);
$decode21=CJSON::decode($json21);
$decode22=CJSON::decode($json22);
$decode23=CJSON::decode($json23);
$this->render('view',array(
'model'=>$this->loadModel($id), 'decode1'=>$decode1
));
}
}
и код view
Код: Выделить всё
<?php
/* @var $this LpuController */
/* @var $model Lpu */
$this->breadcrumbs=array(
'Выбор ЛПУ'=>array('index'),
$model->name,
);
$this->menu=array(
array('label'=>'List Lpu', 'url'=>array('index')),
array('label'=>'Create Lpu', 'url'=>array('create')),
array('label'=>'Update Lpu', 'url'=>array('update', 'id'=>$model->id)),
array('label'=>'Delete Lpu', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Are you sure you want to delete this item?')),
array('label'=>'Manage Lpu', 'url'=>array('admin')),
);
?>
<h1>View Lpu #<?php echo $model->id; ?></h1>
<?php
echo CHtml::beginForm(); ?>
<table>
<tr><th>Участок</th><th>Ф.И.О.</th><th>Кабинет</th><th>Специалист</th><th>Дни приема</th></tr>
<tr>
<td><?php echo $decode1['district'];?></td>
<td><?php echo $decode1['fio'];?></td>
<td><?php echo $decode1['room'];?></td>
<td><?php echo $decode1['speciality'];?></td>
</tr>
</table>
<?php echo CHtml::endForm();
?>