0

Okay obviously in this situation using an ajax call would be the answer. But I have a few questions in the process.

I am preparing to build a mobile app with cordova, and I want to fetch data with javascript. All day today I have been working with laravel and creating some data to store in the database. After creating a router and a controller I see I can access the data in my database as a json object via a uri, this is very cool. Something like http://localhost/players and I get an object.

This is quite similar to the facebook api https://graph.facebook.com/195466193802264 if I were working with the facebook api, inside my javascript I would make an async call to that uri above, obviously the facebook api is more complex with permissions and tokens.

My question is since I setup my uri http://localhost/players, have I created a basic api that I can make a call to that uri and feed my app? Because that is what I will need, it will obviously be in a completely different location than where my laravel is, because I mean it does get packaged into a .apk and installed on the device.

I feel like I am on the right track and I am getting the hang of it, but come the day I need to build my app I want to understand how to consume that data without having to use PHP or be inside that directory.

What I am asking is that true or false, am I thinking wrong here? If so, I can handle saving data but how do I consume this data from an external project?

Michael Joseph Aubry
  • 12,282
  • 16
  • 70
  • 135
  • First of all, ditch Laravel, bad practice framework. Second, (tho it's not the best bundle) You could use the FOSRestBundle from Symfony2 which adapts API standards. And for your other problem: http://stackoverflow.com/questions/333532/cross-site-ajax-requests – Anyone Jan 08 '14 at 09:22
  • I know you hate laravel, but I am liking it and according to this http://www.sitepoint.com/best-php-frameworks-2014/ I would say laravel is kicking ass. I respect your opinion though, I am a noob and I wouldnt really be able to recognize good practice from bad practice, but I have already committed to laravel and it works really well with backbone.js which is my chosen javascript framework. As far as API standards I am just scratching the surface with API's. Ill keep this in mind as I get better though. – Michael Joseph Aubry Jan 08 '14 at 19:31
  • 1
    I had a talk about Laravel with my colleagues, all experienced programmers of which some 7+ years of php usage. They laughed at how stupid Laravel works when they checked the homepage. I can't see any reason why it should kick ass according to that website. Just because a lot of people use it? A lot of people use IE6~8, doesn't make it a good browser though. – Anyone Jan 08 '14 at 19:34
  • You're right, it's big mainly because of the amount of people that use it, not how well the actual framework is. Maybe one day I can see how stupid it is, but I am hardly experienced. I would follow your advice if I didnt already commit to tutorials that cover building applications using laravel. Hopefully I progress quite fast and can move on to something better. – Michael Joseph Aubry Jan 08 '14 at 19:37
  • Maybe after this tutorial and after I get the hang of working in a Rest like fashion I will move on, but for now I am just going to follow what the instructor is doing, it can't hurt to use laravel for a little practice. Thanks for the insight though ill definitely keep it in mind. – Michael Joseph Aubry Jan 08 '14 at 19:39
  • You will start noticing it when you start using dependency injection and unit-tests. Have fun testing when you are dependent on static calls :D Every framework has flaws, but this framework seems to be build around them. – Anyone Jan 08 '14 at 19:40
  • Thanks, well I guess I got to roll my sleeves up and find out whats what. Hopefully I start finding the flaws early on so I can prevent myself from getting to deep into the framework. I really just want to get my feet wet, when I get more experienced I bet I see what you're talking about. The thing is I am trying to build this cordova app by this Sunday, so I don't have time to be jumping around I just need to stick with something I already started. Come next week ill do some research on other frameworks! :) – Michael Joseph Aubry Jan 08 '14 at 19:47

1 Answers1

0

Ofcourse you need some server side scripting language to provide access to the database. So, creating REST or SOAP webservices is the best(and most used) option to let the application talk with the server/database. In your application you'll use an AJAX call to call the webservice and in JS(or a framework on JS like jQuery) you can enter the returned data(callback).

GuyT
  • 4,316
  • 2
  • 16
  • 30