Introduction
I already wrote a similar article, but it was very incomplete and not supplied with examples, so I decided to take a second attempt and try to solve this question most fully!
In this article, all subtleties of development on frameworks will not be considered, since it is not possible to put in one article. However, it is possible to explain in sufficient detail those nuances that will help in choosing to study or implement a specific project. Will compare the Yii2 and Laravel. I understand that this is a rather holivar topic, the result of which usually says that everyone is good in his own way. I, as a person who worked with both, will try to explain my approach to the choice of the framework, and I will try to show the most conspicuously their disadvantages and advantages.
Immediately warn the question of why we are not considering
symfony .
The fact is that symfony is a lower-level framework that is often taken as a basis for large projects, such as writing your own development framework. In principle, it cannot be compared with Laravel and Yii2, since they use its components in their implementations. Symfony is a very powerful product that allows you to flexibly customize virtually any system to fit your needs, but there is little that can be used as ready-made solutions for small typical tasks. On GitHub, you can find a lot of libraries or extensions written for the same Yii2 or Laravel just in symfony.
Yii2
Let's start with Yii2, since this is my first framework that I learned. I must say that this framework is studied very easily, with minimal knowledge of OOP.
pros
- Easy to learn, low development start
- It has many built-in interface solutions.
- Excellent generator of models, controllers & CRUD
Minuses
- Not very flexible route formation
- Poorly developing (the release of new versions)
- Too glued libraries for frontend with backend
Now I will tell about each in more detail. The last of the minuses in general seems to me incomprehensible at first glance, but I don’t know how to say it differently, I’ll explain in more detail what I meant.
')
Easy to learn . The framework is really easy to learn, and after sitting for a day or two, on a small project, you already begin to quietly code on it. There is not enough good literature in Russian to start studying, but this is well compensated by a good reference book in English. As a last resort Google translator. Now I am pleased, it was so before. Most recently, they have updated their site with guides and documentation, and now there are guides in Russian, they are
here . Information on the API has not yet been translated, but there is nothing complicated. Even with a little knowledge of technical English, everything is quite simple, because it simply describes the methods, what they accept, give and what they generally do, the information
here .
Embedded solutions for interfaces can be described as a whole little book, but I will try briefly. Bootstrap is built into the system, unfortunately for now the third, and a bunch of own modules that are associated with it.
You can even poorly own the layout on bootstrap, and at the same time using the built-in Yii2 methods to make pop-up modal dialogs, windows, drop-down lists, spoilers, etc.
Here is a small example that can be found on a whole bunch of websites, and even in the official documentation of Yii2:
Sample modal windowuse yii\bootstrap\Modal;
Modal::begin([
'header' => '<h2>Hello world</h2>',
'toggleButton' => ['label' => 'click me'],
'footer' => ' ',
]);
echo 'Say hello...';
Modal::end();
, <h2>Hello world</h2>, click me, , «Say hello...» « ».
'data-target="#id-modal"' , . Yii2 — , , backend — . , . , .
, , - . , , , , - ,
echo Select2::widget([
'name' => 'state_2',
'value' => '',
'data' => $data,
'options' => ['multiple' => true, 'placeholder' => 'Select states ...']
]);
, Select2, kartik-v,
GitHub.
, input select
Select2.
, , - , , .
, — , . Yii2, GUI , . , , , , , . ,
gii.
. CRUD . laravel, , , , ( , ),
foreign key, «» , , .
, , .
CRUD , , . .. , CRUD . , , , .
- . , , , . , . . CMS . , , Yii2 .
. , .
. Yii :
public function actionIndex()
{
return $this->render('index', []);
}
action ,
Index. ,
actionArticlesList, :
/_/articles-list. , :
, :
[
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<module:\w+>/<controller:\w+>/<action:(\w|-)+>' => '<module>/<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:(\w|-)+>/<id:\d+>' => '<module>/<controller>/<action>',
],
],
]
rules, . , ,
.
, . , Yii2 bootstrap-3, .
, — . , , (views). , , , php html, .
WebPack, Gulp . , Yii2 — . , css assets .
, ? !, frontend backend, Yii2 . .
Laravel
Yii2, Yii2
WebPack, , , frontend WebPack .
laravel mix, WebPack, , , .
mix'alet mix = require('laravel-mix');
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
, . , frontend .
, . , frontend .
scss, Vue, Laravel, Vue.js .
Blade, Twig, . , , Twig Blade. Blade, , , Twig , Blade Laravel.
. symfony, ,
Route, .
Yii2 , , . , , - (POST, GET ..), . , Blade.
Route::get('/dashboard/newsList', 'DashboardController@newsList')->name('dashboard/newsList');
Route::middleware('auth')->delete('/dashboard/newsList/news/{uuid}', 'APINewsController@DeleteNews');
middleware, - . . middleware ,
routes.
. , HTTP- .
Yii2, , , , . Yii2
yii\rest\ActiveController — REST FULL API, , .
, Laravel REST API. ,
« REST API»Laravel . , , . , .
.
, Laravel. , ! , , - .
. ,
Illuminate\Database\Eloquent\Model,
where, select .., . . , , . . , , , IDE . — IDE-helper, .
GitHub. GitHub .
« Yii2» , . Symfony Yii2 . , , , , .
, Laravel Yii2, , Yii2 , . , .
. , , . , , . , , .
. , Yii2, . , , , .
Laravel Yii2, - - . , , , . Yii2 — . .. , . , , .. , , Yii2 . , . Yii2 .
,
« ?». — .
Yii2 , , .
Laravel — . frontend'a backend'a.
, , . ! !
SymfonyYii2Laravel:
Yii Select2 kartik-v.
Select2.
Yii2 ( )API Yii2 ( ):
IDE-helper Laravel (GitHub)Laravel ( , )