Sometimes a convenient method to restrict access to certain sections of a website (such as the administrator panel or confidential data) is to use access restriction with .htaccess (or, alternatively, basic authentication). Of course, with scripts, this can be done more elegantly, conveniently, and sometimes even more securely. The thing is, all the information needed to gain access is sent with each request in the form of headers. But if this is not critical, then it can be used; it is probably the fastest option.
In this note we will learn how to create and handle forms in Symfony framework.
Forms can be created "from scratch" or using an ORM (object-relational mapping) to generate forms based on database tables. Let's start by exploring the second option. In practice, these types of forms are most commonly encountered since in most cases, the data entered in the form needs to be stored somewhere (in a database).
As you know from the lessons, the public directory of Symfony framework by default is web/, and the framework directories lie next to it. This means that for normal operation and pretty URLs, the DocumentRoot on the server should be set specifically to the web/ folder. But this is not always convenient and not always possible on hosting. In most cases, you will not have the ability to edit the DocumentRoot.
In the previous note, we learned how to write simple queries to the database using Doctrine. But often we have to write something more kinky, with these joins of yours =). Here we will try to understand how it's done.
Today I came across an unpleasant problem - when using block layout, I needed to stretch a block to fill the empty space of the parent element vertically (div expand). Naturally, there is no difficulty in doing this horizontally - simply set the display to block and it will work =).
So, we already know theoretically (here you can read), why Doctrine, what advantages it provides compared to "bare" sql queries. Now we move on to practice.
When studying a new framework or web programming language, you may sometimes feel confused and ask yourself: When can I consider that I have learned the product to a decent level? When can I say that I know it, and if there are some things I don't know, I can quickly grasp/read them in the manual/search for them on Google?
Sometimes you need to convert the table engine MySQL in an existing database.
For example, I needed to create relationships between tables. To create them, the tables must be InnoDB (to support foreign keys).
Old Wordpress (and other) projects use MyISAM because until version MySQL 5.5.4 it was the default engine. But it doesn't support many useful features, such as foreign keys, transactions, etc. All these features are supported by the more modern engine InnoDB, which is now used by default.
After reading this article, you will be able to create relations in MySQL database using phpmyadmin. If for some reasons you don't want to use phpmyadmin, please look at SQL queries below.
So, what reason to store relations in the database? After all, your application also solves this task. Actually, it's all about the restrictions and actions upon changes, which can be set using relations.
For example, you can deny deleting category while any article connected with it. Or remove all articles if category removed. Or set NULL in relation field. In any case, using relations increases fault tolerance and reliability of the application.
You need to use an InnoDB engine to create a relation. Only this engine supports foreign keys. If you have MyISAM tables, you can read how convert it to InnoDB.
So, in the previous lesson we learned how to use the Twig template engine in the Symfony framework. Now we know how to write a simple template. But we don't know how to include external components (stylesheets, js, images), as well as create links to our own pages.