I\'m creating a CRUD-based web project, and am thinking about using a server sid
ID: 647258 • Letter: I
Question
I'm creating a CRUD-based web project, and am thinking about using a server side MVC framework (such as CodeIgniter or Laravel) in tandem with a client side MVC framework (such as AngularJS). Is this a fairly common approach? After all, it's clear that I need something on the server, and that doing MVC on the client as well can enhance my application. But I feel that two MVC frameworks on the same project would just get in the way of each other and lead to disproportionate complexity and repetition.
What kind of approach or architecture would help me get the best out of both MVC frameworks when using one on the client, the other on the server?
Explanation / Answer
Laravel and AngularJS actually work quite well together; there's a good video on Laracasts about it and a few good articles online.
In general you wouldn't want to use multiple MVC frameworks in one project as it increases bloat, as well as a lot of redundancy. Your average PHP MVC framework will include an ORM, Templating engine, router and so on - components that you only need one of. In fact, using two will most likely increase complexity and introduce conflicts.
The exception here is where frameworks are separated clearly, like in the case of a server side framework and a client side framework. Both frameworks are actually doing completely different things.
However, if you want to combine the use of Laravel and AngularJS then you most likely wouldn't be using all of Laravel's features. The recommended strategy is to implement something akin to a REST API using Laravel's Resource routes - and to treat all interactions as AJAX API calls.
This means you won't really be using the V of Laravel; I.e Views with Blade. (Apart from perhaps the layout for initially loading the app)
A quick google of "Laravel and AngularJS" returns a whole plethora of articles, but perhaps the best resource is this sample project:
Github example: https://github.com/bktz/Laravel-4-AngularJS-Starter-Site
A noteworthy article was this one though:
http://scotch.io/tutorials/php/create-a-laravel-and-angular-single-page-comment-application
It discusses the proposed structure of such an app, as well as the resource routes I mentioned above.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.