getting content from database and adding it into a multidimensional array
<!-- 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"]
)
);
};
}
<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>
$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);
{
"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"
}
]
}
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;
}
});