Last active
August 10, 2016 09:26
-
-
Save BinaryGeometry/9090266 to your computer and use it in GitHub Desktop.
Configure codeigniter-restserver for use with Ember.js
This file contains hidden or 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
First off you need to modify application/config/rest.php | |
``` | |
$config['rest_default_format'] = 'json'; | |
``` | |
This will ensure that when your api call is made the server will return json without an additional segment. | |
You must then create an api controller that will return your codeigniter model in the correct format for Ember.js | |
``` | |
<?php | |
require(APPPATH.'/libraries/REST_Controller.php'); | |
class Api extends REST_Controller | |
{ | |
public function index_get() | |
{ | |
$array = array( | |
'yourEmberModel' => $this->db->get('menu')->result() // assign your CodeIgniter model to an array with name yourEmberModel | |
); | |
$this->response($array ); // pass this array to the restserver rather than the defaul model | |
} | |
} | |
``` | |
Now when you visit localhost.com/index.php/api you will have the json returned in correct format for use with Ember.js | |
``` | |
{ | |
yourEmberModel: [ | |
{ | |
id: "1", | |
menu_section: "Mic dejun", | |
section_order: "1", | |
item_name: "Kinder Smoothie", | |
weight: "350 ml", | |
price: "14", | |
ingredients: "lapte de migdale, polen crud, ananas, calse deshid" | |
}, | |
... | |
} | |
``` |
i am working with ember and codeigniter, how can i handle file upload with these ,i have no idea
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you