function view($unit_id) { $app = get_app(); $unit = Unit::find_by_id($unit_id); if ($unit) { $app->render('Units/view.php', compact('unit')); } }
function upload_for_unit($unit_id) { $app = get_app(); // GET if ($app->request()->isGet()) { $app->render('Images/upload.php', array('type' => 'unit', 'id' => $unit_id)); } // POST if ($app->request()->isPost()) { $unit = Unit::find_by_id($unit_id); if ($unit) { $results = \Controller\Images::upload(); if ($results['is_success']) { $unit->image = $results['md5_name']; $unit->save(); } echo json_encode($results); } } }