-
-
Save RyanDawkins/af1c5365579f8824b80c to your computer and use it in GitHub Desktop.
Parent/Child REST Controller for CRUD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Routing | |
'api/:parent/:pk/:child/create' => 'api/parent/child', | |
// controller/api/parent.php | |
<?php | |
class Controller_Api_Parent extends Controller_Crud | |
{ | |
public function get_child() | |
{ | |
$parent = "Model_Api_Orm_".ucfirst($this->param("parent")); | |
$child = "Model_Api_Orm_".ucfirst($this->param("child")); | |
$parent_model = new $parent(); | |
$parent_orm = $parent_model::find($this->param("pk")); | |
$child_model = new $child(); | |
$child_orm = $child_model->from_array(Input::json()); | |
$child_orm->save(); | |
return $this->response(array( | |
"parent" => array( | |
$parent => $parent_orm->to_array(), | |
), | |
"child" => array( | |
$child => $child_orm->to_array(), | |
), | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment