Skip to content

Instantly share code, notes, and snippets.

@aurelkurtula
Last active December 23, 2015 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aurelkurtula/6648857 to your computer and use it in GitHub Desktop.
Save aurelkurtula/6648857 to your computer and use it in GitHub Desktop.
getting content from database and adding it into a multidimensional array
App = Ember.Application.create();
App.IndexRoute = Ember.Route.extend({
model: function() {
return App.Item.all(); //get the item object and it all() function
}
});
App.Item = Ember.Object.extend();
App.Item.reopenClass({
all: function() {
var links = [];
$.getJSON("file.json").then(function(response) {
response.post.forEach(function (child) {
links.pushObject(App.Item.create(child));
});
});
return links;
}
});
{
"post": [
{
"title": "smathing magazine",
"description": "some description",
"url": "http://smashingmag.com"
},
{
"title": "Boagworld",
"description": "some one",
"url": "http://boagworld"
},
{
"title": "Css tricks",
"description": "chris coyer",
"url": "http://css-tricks.com"
}
]
}
$info=array();
while($row = mysqli_fetch_array($result))
{
$info['post'][]=$row;
}
// then adding it to a json file
$posts = array('post' => $posts);
$fp = fopen('file.json', 'w');
fwrite($fp, json_encode($posts));
fclose($fp);
<script type="text/x-handlebars" data-template-name="index">
<h2>Welcome to Ember.js test</h2>
<ul>
{{#each link in model}}
<li>
<a {{bindAttr href="link.url"}} target="_blank"> {{link.title}} </a>
<a {{bindAttr href="link.delete"}}> (delete) </a>
</li>
{{/each}}
</ul>
</script>
<!-- reading the json file and sorting into a multidimentional array -->
$string = file_get_contents('http://localhost/2013new/emberforbeg/my/test.json');
$json_articles=json_decode($string,true);
$json_entries = count($json_articles['post']);
foreach ($json_articles as $key => $value){
$posts = array();
foreach ($value as $key => $values) {
array_push($posts,
array(
'title' => $values['title'],
'description' => $values['description'],
'url' => $values["url"]
)
);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment