Answer the question
In order to leave comments, you need to log in
Is it possible to understand OOP while learning YII2?
Good afternoon, dear forum users, first I will tell you a little about myself.
I've been doing web development for about 1.5 years, I'm quite tolerably typesetting, I can finish some script for myself, create a site on wordpress, Joomla, Bitrix, medium complexity, I'm familiar with php at the level of arrays, cycles, conditions, cookies, sessions, I roughly understand php interaction with mysql
In general terms, the concept of OOP. (since I started to study java with OOP, but didn’t go further)
Actually, the question itself is, is it possible to start studying yii2 and figure out how OOP and MVC work in php?
Of course, I understand that there is no place without theory, but I was convinced from my own experience that in practice the material is absorbed much easier.
Can you give me some good advice on which way to go?
Honestly, I myself understand that at the moment I'm stuck on sites for housewives, and this is depressing.
Thank you all in advance
Answer the question
In order to leave comments, you need to log in
How to say Yii is a box of wrenches. Is it possible to understand from the box - why the keys? Well, you can, if you use the keys for a long time as the developers write, then you will understand over time, but there is a risk of falling into "I do as they said, why - I don't know."
If the question is about OOP: developers needed to write less repetitive code so as not to change the same thing 10 times. Let's go in order.
Imagine an associative array (key-value).
Now imagine a function, any, let it be abs () - a modulo number.
And now throw this function into your array in place of some key, that is, you seem to get $array["abs"], where the function itself lies.
What is the difference between a function and other data? You can write data, or you can read it. And you can still perform the function. Thus, when you threw it into the array, you don’t have a function there, but its blank, for execution. And you can call it, but not as abs(), but as $arr['abs']() - which will look the same (everything is more complicated under the hood, but forget it for now, you don't need it)
Now imagine what you have there are ten such $arr arrays. And what, in each now to stick the function that you just stuffed into the first one? No, why. To do this, there are "classes" - which describe the appearance of the future "array".
Thus, OOP is when you first describe the appearance of an array, and then create these "improved arrays" according to the described form.
There is a theme here - to take an array type (class), and on its basis to make another class, so as not to rewrite it first.
There is a topic here - create your own data type and check it when passing from function to function.
There is a topic - that in addition to the array type, you can set an even higher degree of organization "requirements for the type of arrays" - that is, the interface - "all the described array types must have such and such a method and such and such properties, if not, kick the developer that he fool"...
For the most part, many of these chips and movers are the fruit of a sick fantasy of the mind of developers that require self-realization. Well, that is, you can download the Excel price list and parse it on arrays, merge two price lists into one in several fields - you can also use arrays.
All this rigmarole with OOP is when you really need rocket artillery - you want to write code in which - don't put anyone - a moron or a smart guy or someone else - he can't break anything. But he still can, so often work on OOP falls into a cycle in the style of "I edit something that will not be useful to anyone, but I know that one day it will fall, and therefore I edit it."
OOP should be thought of as a means of reducing the amount of code. If, for example, you have two suppliers and two different upload files, and the actions in them are the same, you can resort to OOP by making the type "Supplier" and describing in it - what it can do with its "instances-objects-enhanced_arrays" etc.
Before you think you can't do without OOP, you need to understand that anything CAN be done without OOP. Just the amount of confusion if you drop this code and come back to it in a month and no longer remember what, where and when - there will be more. Classes create a kind of descriptive structure of what is happening, and therefore often in large projects writing in OOP is longer and harder than without OOP.
That is, the thing was developed in order to write less, but in fact, for understanding, all the variables in the camel are written, and as a result, the code becomes even larger, but it is of the "understandable" type. And then they will sort out expensive employees, because the cheap ones cannot write this understandable code, so the guys swarm in their heads, and the money brings sales later. Don't fall into that trap.
You will need OOP when you have a very distinct feeling that "damn, what a shitty language this is, I got so sick of writing this thing every time again, why didn't they do it right away?" - that's when you need to do OOP, and then it will be easy to understand.
I'm not talking about something like "it's still early" and so on. I'm talking about the fact that there are a lot of things in which you can give time, more interesting and useful than plunging headlong into this dregs, which in fact, apart from a sense of imaginary superiority, will give you nothing. Just do it as you like, and only when you decide to set behavior for your arrays - like "when assigning a key to the `name` field, automatically create a `code` field with such and such content" - then you can really smoke what else you can stir up here.
Yii2 is not a panacea in your case. It's just a framework, it will allow you to do things that are very vaguely reminiscent of proper OOP. Moreover, having studied OOP by framework, you will perceive all OOP through the prism of decisions imposed by the framework.
If you want to improve your theory, watch courses, webinars, and then start implementing complex things. Stuff your bumps, gain an understanding of where and how it would be better to write code. In the end, find some OpenSource on the framework and study it already.
You can, I just do it ... BUT:
It is better to start learning native OOP, since the framework defines a certain style that is used only in it. Of the explanatory materials, there are course records from the "Specialist" center.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question