How to work layouts and javascript in php frameworks

Asked

Viewed 336 times

0

I am doing a course on frameworks and would like to know the following. The tool name itself already speaks: PHP framework

Question: You mean the organization of html layouts and scripts based on Javascript libraries is on the user’s account? He does or puts where he wants his layouts and scripts, in fact everything that is not PHP?

There is logic to apply layouts and js scripts within a PHP framework or the framework concern is specific to the PHP?

  • 1

    Don’t get it, you mean MVC? I’m one of the developers of a PHP framework called easyFast. http://bruunofco.github.io/easyfast/ one of the objectives is to maintain the pattern of development of business rules / code organization. In addition to implementing the ORM that greatly facilitates communication with the database. For Layout (TPL/HTML, JS, CSS), there are patterns to be followed but we don’t focus on that in our framework for example.

1 answer

6


What is a framework

Not every framework is used for software architectures like MVC, so the term framework will not always refer to MVC/HMVC/MVCP, etc.

The term framework is used to refer to abstraction of common codes and can be front-end, back-end, used in web, mobile or desktop applications. Therefore the term does not refer only to cakephp, Laravel, Asp.net-mvc frameworks, etc.

The term Framework is being used strongly to refer to cakephp, Laravel, etc because of their popularity specific frameworks and because with time and need today to accelerate development we use such frameworks, to avoid (even if many use without knowing that this is the reason) problems already known during the development phase and the maintenance phase.

Then a framework can be used to build a project on MVC, HMVC, REST, etc. These answers should help you better understand this:

What is MVC

Frameworks like cakephp support MVC, it doesn’t mean you have to follow this pattern to understand what MVC ( and its like :) read this reply:

Note that the MVC standard came before the internet, so the answer is more web-oriented

Javascript and PHP Frameworks

About your question:

You mean the organization of html layouts and scripts based on Javascript libraries is on the user’s account? He does or puts where he wants his layouts and scripts, in fact everything that is not PHP?

Is it logical to apply layouts and js scripts within a PHP framework or is the concern of the framework specific to PHP?

If you understand the logic of MVC in PHP frameworks like cakephp, then you know what it is View, MVC in PHP is generally geared towards back-end organization and usually you organize the front-end (javascript and css) as you see fit, however they should suit Views or else the Views should fit the . js, ie the communication include css and js files on the page is something that is more in the View layer, however although many think that models are database abstractions, this is not entirely true, the models perform the task of business rules and they can even define indirectly the js that will be called (note that said indirectly).

In short, the layer View is who most directly takes care of the layout, javascript and css and it is in it that you will work it.

Already the calls of Controllers/actions can be done by javascript and we usually do this by defining routes, however javascript calls the Route and the Route calls the Action, note that there is a lot of variation of how each uses the MVC, so not everything will be exact as each person says.

Note that cakephp has libraries that help you use javascript and layout with your Views:

What is FLUX

Facebook created something alternative to MVC, it is called Flux, this caused some confusion, since many MVC web frameworks are geared towards back-end, Flux works on both sides and its Controller (Dispatcher) is a single controller that organizes tasks, I won’t go into much detail but it is a good follow-up if you want to work in order to organize the front-end and back-end (at least this is the goal).

This is a personal opinion of mine, regardless of how Flux is organized, pro MVC does not exist an exact pattern and if you look well Flux is nothing more than an MVC with a main controller (Dispatcher) which as far as I know already existed, only not written in the same way, basically we can say that Flux is a name more commercial of MVC from Facebook

Structure of Assets folder

It is good to remember that there is no official standard or anything, each one makes how to feel better, however a simple example of organization of the files . js, . css, . mp3, etc would be something like:

projeto
├── .htaccess
├── Framework
│   ├── src
│   └── application
└── public
    ├── index.php
    └── assets
        ├── images
        ├── js
        ├── css
        └── media

This is just a basic example, and you can modify your need (or understanding).

Completion

Yes, in current popular frameworks for PHP generally the organization of the front end is as you wish and I believe the intention is for you to use specific things for the front end like Bootstrap and jQuery-ui.

The purpose of this MVC frameworks in php is to create routes and models to better organize your project and faster. Keep in mind that MVC frameworks are for easy work, it doesn’t mean you need or should always use frameworks ready.

If you notice anything that you disagree with in my reply do not hesitate to comment, comment, really the subject is a little extensive and easy to confuse.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.