B
B
Begetan2011-03-02 11:08:51
Design
Begetan, 2011-03-02 11:08:51

First steps in PHP, does it make sense to start with MVC?

I had a task:
There is a foreign Internet site, I made for it the translation of pages into Russian on the fly. Now I want to embed shopping-cart into the translated site. A cursory examination of the issue showed that almost all popular free scripts are written in PHP.
So you need to learn PHP! It’s worth saying here that the project is more of a hobby for me, which may become a startup.
My limited programming experience includes a decent knowledge of SQL, a little knowledge of Perl, an understanding of what C is, and a basic understanding of the object paradigm. But I used to dislike PHP for a mess that mixes code and design. However, I found an Opencart script that is written according to the MVC model, which means that the porridge that frightens me is sorted out in it.
However, a cursory study of the code gave rise to doubts. I will try to formulate these doubts in the form of simple questions to the Guru. Some questions may seem silly, but do not forget that I looked inside php 3 days ago, and I thought about MVC a week ago.
Rushed!
1. Tell me a simple Russian tutorial on php version 5.1. Particularly interested in the nuances of templates and work with the database.
2. Is OpenCart a good example or a code to get familiar with the language?
3. Why are there so many files in PHP? Because a separate class = a separate file or is it a code style? Is it possible to have smaller files, I'm not used to it :)?
4. Is there any simple IDE for PHP under Windows. Previously, vim under unix was enough for me, but with a bunch of PHP + MVC files it turns out damn inconvenient. Can the IDE generate a php object relationship diagram based on how SQL database diagrams are drawn?
5.1 How to do html layout for php? Is there a noob coder who wants to learn Dreamweaver, will this help us?
5.2 MVC under PHP is it needed at all? When you run the script, hundreds of files are loaded, very low performance. What if my project shoots up and there will be thousands of visitors, I will have to abandon PHP, can I do it right away?
6. Or maybe not php at all or what for MVC? But I don’t want to write a store script from scratch!
Advice, teachings, peremptory statements, reasonable holivars and philosophical reflections are welcome in the answers! All this can fall into a brain completely clear of any concepts.
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

19 answer(s)
J
Jazzist, 2011-03-02
@Jazzist

My limited programming experience includes a decent knowledge of SQL, a little knowledge of Perl, an understanding of what C is, and a basic understanding of the object paradigm.
MVC already loves and waits for you.
1. Tell me a simple Russian tutorial on php version 5.1. Particularly interested in the nuances of templates and work with the database.
php.su
2. Is OpenCart a good example or a code to get acquainted with the language?
A good example is a popular MVC framework.
3. Why are there so many files in PHP? Because a separate class = a separate file or is it a code style? Is it possible to have smaller files, I'm not used to it :)?
1. It is more convenient to work this way, and this convenience has a mega-positive effect on the speed and efficiency of work. "Divide and rule"
2. Unused fragments may not be loaded - thus the lightness and low resource consumption of the final application is achieved
3. Of course, you can do less! Frameworks are waiting for you :)
4. Is there any simple IDE for PHP for Windows. Previously, vim under unix was enough for me, but with a bunch of PHP + MVC files it turns out damn inconvenient. Can the IDE generate a php object relationship diagram based on how SQL database diagrams are drawn?
1. Work with Linux, there are a lot of convenient IDEs. Under Windows there will be problems (holivars go to Google and according to manuals, including PHP User Guide)
2. It is possible, but in most cases a simple database structure is a great advantage
5.1 How to make html layout for php? Is there a noob coder who wants to learn Dreamweaver, will this help us?
1. You don't need Dreamweaver, you need a tutorial and CSS2 specification. A good place for this question is htmlbook.ru
2. HTML layout for PHP is no different from HTML layout for something else. She is on her own.
5.2 MVC under PHP is it needed at all? When you run the script, hundreds of files are loaded, very low performance. What if my project shoots up and there will be thousands of visitors, I will have to abandon PHP, can I do it right away?
1. Yes, it is necessary. But it is possible without it.
2. Loading files does not reduce performance (I can show an obvious proof, but google it better).
3. The ability not to load too much - performance increases
4. This is not a reason to abandon PHP. Of course, there are reasons ... but not this one. PHP will most likely not let you down.
6. Or maybe not php at all or what for MVC? But I don’t want to write a store script from scratch!
Python+Django. MVC is at least a good school that hasn't hurt anyone yet.
All this can fall into a brain completely clear of any concepts.
Then look again at the answer to question #6 :)

S
SSar, 2011-03-02
@SSar

1. I have not found anything better than the Russian chm-version of the help downloaded from docs.php.net for 7 years.
3. Everything depends on you as a developer. I met many examples where there are a lot of files and where everything is in one.
4. I liked the free Komodo Edit + htmltoolkit (you can also add modules to it from the Internet), from paid Adobe Dreamweaver CS.

A
Anton, 2011-03-02
@AntonMinsk

>> 1. Tell me a simple Russian tutorial on php version 5.1. Particularly interested in the nuances of templates and work with the database.
Version 5.1 is probably already too old, so 5.3 is better right away, I think that there should not be any compatibility problems with some things already written. There are a lot of books on PHP, I personally mastered PHP using the book “PHP5-library of a professional”, it was a long time ago ...
>> 2. Is OpenCart a good example or a code for getting to know the language?
Let someone else answer this question =)
>> 3. Why are there so many files in PHP? Because a separate class = a separate file or is it a code style? Is it possible to have smaller files, I'm not used to it :)?
Can! but I know from personal experience that maintaining such a structure is much easier. There is a moment with script brakes when include, but this is solved by autoload, eaccelerator, etc., etc. there are acceleration options
>> 4. Is there any simple IDE for PHP under Windows. Previously, vim under unix was enough for me, but with a bunch of PHP + MVC files it turns out damn inconvenient. Can the IDE generate a php object relationship diagram based on how SQL database diagrams are drawn?
It’s already a matter of taste, someone uses Eclipse, someone uses Zend (I personally still use 5.1 ZendStudio, I know it’s old, I couldn’t get used to anything else), PHPExpertEditor, in my opinion, is still there, in general, I can find can.
>> 5. How to make html layout for php? There is a noob layout designer who wants to master Dreamweaver,
Just make up, no matter what.
Look at template engines, for example Smarty, I have been using XSLT for a long time, I have a framework for it. If you stick to MVC, you will definitely need a template engine
>> 5. MVC under PHP is it needed at all? When you run the script, hundreds of files are loaded, very low performance. What if my project shoots up and there will be thousands of visitors, I will have to abandon PHP, can I do it right away?
Without MVC, I'm already very good. I can’t imagine my projects well, I already wrote about performance above. If the project succeeds, it will be good =) I think in this case there will be solutions. Very pleasant problems are to sharpen the architecture for a high load, especially when it already exists. Well, without a good architecture, supporting a large project will be much more difficult, so I would advise you to stick to MVC
>> 6. Or maybe not php at all or what for MVC? But I don’t want to write a store script from scratch!
Well, if you don't want, then PHP

M
marazm, 2011-03-02
@marazm

Ask yourself another question: “does it make sense to start with PHP?”
No, seriously, look in the direction of python or ruby

S
shifty, 2011-03-02
@shifty

A good manual for PHP - manual.pohape.ru

D
DeNnEr, 2011-03-02
@DeNnEr

>a study of the issue showed that almost all popular free scripts are written in PHP.
>So you need to learn PHP!
It's like drawing a conclusion about how the state should work by looking at Russia.
In short, now you need to develop sites either in Ruby or Python. For newcomers, Ruby is easier. For very complex sites, Java is also possible. I won’t write more about the choice of tools here, because. it takes too much time and text - you can write in a personal and ask questions.
As for MVC, it's not something specific, but just a pattern, an idea, nothing else.
Your question can be boiled down to whether it is necessary to learn a web framework or PHP knowledge will be enough.
PHP, Ruby, Python are just programming languages, nothing more. PHP, of course, has the ability to develop "like this", but this has always been and will always be bad form. First you need to learn the language, and then the toolkit for developing the application. It's like learning what concrete is made of and starting to build a house: a huge process time will be taken up by building and creating the tools that are already there. In the case of a web dev, you will create your own analogue of the web framework and the MVC pattern.
Well, now specifically, on the questions:
1) I can give links, but I really want you to think about whether you really need to take ColdFusion Today.
2) Bydlokod.
3) If you are used to formatting large projects in the form of several code files, you like to be proud when you have to say “I have a function in the 2342nd line of code”, then you wrote a redundant code and you need to relearn. Apparently, this was not entirely true, because the division into sub-files is a modularity in development, this is convenient, because. each file includes one functionality of the entire project structure.
In the case of php, there is the very need to separate files. You can learn more from the history of PHP.
4) NetBeans is used by acquaintances, likes.
The web framework builds the project structure, it does this in the form of creating subdirectories, like: models, controllers, templates. As a result, creating a project is very easy and simple, it can be done even in a notepad. I work in Emacs and the project tree with the editor is enough for me.
There is no point in “drawing” a project scheme, because except for you, the programmer, it will not mean anything, and it will not make more sense than the unix tree command gives.
5.1) HTML layout is always HTML layout. Just to add dynamics, special template languages ​​are used. In fact, they do not require anything so complicated: you just write HTML code, but where it is needed, you insert logic elements. That is, where you need to insert the number of visitors, instead of a number, you write something like: {{ mynum }}.
5.2) MVC, like design patterns in general, is needed everywhere and always. Ignoring them leads to the creation of bicycles.
6) You wanted to write your web framework (and it would have been) in PHP, an implementation of the MVC pattern, but do not want to write a store from scratch?
Just go here: rusrails.ru/ There you will find answers to all questions, you will find the best tool for a novice web developer.

A
Alexander, 2011-03-02
@akalend

>2. Is OpenCart a good example, or is it just code to get to know the language?
This is something in between, but the best that we found from Opensource. There are a lot of blunders, almost 30-60% will be rewritten. But is it still better than developing from scratch?
>3. Why are there so many files in PHP? Because a separate class = a separate file or is it a code style? Is it possible to have smaller files, I'm not used to it :)?
this is such a style, and not only in PHP: one class = one file
, you can merge everything into one file - then there will be a mess
> 4. Is there any simple IDE for PHP under Windows. Previously, vim under unix was enough for me, but with a bunch of PHP + MVC files it turns out damn inconvenient. Can the IDE generate a php object relationship diagram based on how SQL database diagrams are drawn?
Zend, Eclipse, PHPEdit, PhpEd the
above IDEs do not do this, but you can configure phpDoc or I recommend Doxygen - which turn the documented code into HTML documentation
Zend has a built-in PHPdoc
Doxygen - generates graphic drawings and class interaction diagrams
5.2 MVC under PHP is it needed at all? When you run the script, hundreds of files are loaded, very low performance. What if my project shoots up and there will be thousands of visitors, I will have to abandon PHP, can I do it right away?
> I have an MVC project at 50-60K until it crashes. It falls only for those who have crooked hands, so MVC is definitely needed. Do as it is, it will start to fall - look for bottlenecks. As for Opencart, we are completely rewriting the frontend so that it doesn't crash... (well, plus adding our branded features)
>6. Or maybe not php at all or what for MVC? But I don’t want to write a store script from scratch!
you are doing a project, it’s up to you to decide ...
on the topic - answered above

H
Horse, 2011-03-02
@Horse

3. You can do less, but you don't need to. There are many files because people are used to tying a specific piece of implementation to a file.
5.1 First you do the layout on html, and then, depending on situations and conditions, you give pieces of html to the client.
5.2 YES! Otherwise, it will be extremely difficult to make changes to the design, the structure of the database ... When there is a high load - there will be a cache, many servers, maybe your own database, and MVC should be left out (of course, for distributed systems it will change)
6. php can be replaced with python, java , asp.net, perl, ruby. MVC can be replaced by MVP, MVVM.
If not for long - php MVC. If for a long time, I recommend python and read something more serious about OOP.

M
Max Kuznetsov, 2011-03-02
@pluseg

I will answer only some questions:
2) OpenCart is a normal code for getting to know the language :) it's like reading a book: regardless of whether the book is good or bad, after reading it, you get a profit in the form of understanding how to write or not to write.
3) Yes, this is a code style that helps in case of an error to immediately localize it. Considered good practice.
5) Layout for php should be done in the same way as a regular page, only "interspersed" php code. If you use any MVC framework, then it becomes easier to typeset, just because everything is separated - you slip the data into the viewer and that's it.
According to my long-standing experience (7 years ago, when I just took up the web), I do not advise using Dreamweaver, because it uses (or used, but now everything is fine?) Dirty markup with extra elements, with extra absolute positioning.
5-2) possibly low performance - due to the quality of the scripts, try to optimize.

V
Vyacheslav Plisko, 2011-03-04
@AmdY

Begetan, garbage is
1. because you yourself do not know how and you will get what.
2. the programmer is just able to build an architecture for changing requirements, and you will write each time from scratch.
3.and your time is free? learning php and programming is a hundred times more time than writing a project.
4. any normal programmer, without even investing his soul, will make the project better than a self-taught person with no experience, even if he tries his best. Effort is no substitute for experience.
5. you are ready to throw away a lot of time, sacrifice your personal life in order to write a clumsy startup. which fails either because of bad ideas and PR, or because of the technical implementation curve?
bullshit, bullshit, bullshit. why some people hate and do not appreciate themselves so much, inventing adventures for their ass.

S
SMiX, 2011-03-06
@SMiX

Regarding point 6, I can offer Spree .
The engine is written in Ruby, and the authors try to keep up with the times and constantly release new versions using modern tools (migrating to new authorization engines, updating the code to be compatible with current versions of rails, etc.). There are a large number of plugins.

V
vanxant, 2011-03-06
@vanxant

Regarding 4 - I personally tried a bunch of everything, so far I have settled on NetBeans as an IDE and PHPEdit as a replacement for Notepad.

D
Dan, 2014-05-11
@golotyuk

Regarding the question about MVC - I would not advise looking at it as something mandatory - it's better to try to understand why it is needed. Well, it’s better to rush into hardcore in stages, the main thing is not to be lazy to change bad code (which cannot be avoided) while acquiring new knowledge.
I recommend reading Web development for beginners . There is a very basic level, but it may be useful to start over.

V
Vladimir Chernyshev, 2011-03-02
@VolCh

MVC is an application design pattern, it has nothing to do with the language or the number of files, just as it has nothing to do with OOP. This is the division of the entire application logic into three levels. I once created an MVC application in php as part of a procedural approach. Each request is two inclusions, and purely theoretically, one could do without them, but aesthetically ugly.

V
Vyacheslav Plisko, 2011-03-03
@AmdY

if this is a hobby for a startup, then there is no point. ordering a normal project from experienced programmers is several orders of magnitude more profitable than learning a programming language. and then kill the startup implementation curve.

S
sskorykh, 2011-03-07
@sskorykh

1. I use www.php.net/manual/en/index.php as a reference.
2. I have not seen OpenCart, but I would recommend taking some framework and writing an application using it. I would recommend Kohana3 as the easiest and fastest to learn. Kohana3 does not have its own template engine, but you can attach an external one. I recommend Twig.
3. I do not recommend violating the generally accepted approach of separating classes and files, it is better to store each class in a separate file. This approach also has practical implications. If autoload is implemented, then the system must know exactly where the required class lies.
4. The most convenient free IDE for me was Netbeans. Generating a class diagram for languages ​​like PHP is a rather non-trivial task.
5.2 MVC is a must! Learn to write correctly from the very beginning. Systems written without separation of logic and presentation can be written, but it is almost impossible to maintain.
The problem of low performance is rather far-fetched. When using autoload, hundreds of files are not loaded. I would not recommend writing a scalable solution based on “suddenly the project will shoot”.
6. PHP may not be the most perfect PL, but in capable hands, I think, it is no worse than Ruby or Python. I was lucky in the sense that I first learned to write in Java, and while mastering PHP I already had a clear idea of ​​\u200b\u200bhow the application architecture should look like.
But I would not advise writing a store from scratch. To begin with, I would advise you to put the store on a typical engine, and when it turns out that the topic has really gone, then you can already think about writing your site. But it is not a fact that the need to rewrite the site will arise at all.

A
Alexander, 2013-08-08
@kryoz

I would recommend starting with PHP 5.4/5.5 right away so you can use namespaces, closures, and syntactic sugar. Of course - only OOP, and hence MVC. It’s better to get used to this style of programming right away than to be retrained from a govnocoder into a person.
To do this, find something suitable on github or get a job as a junior in some young project.
Be sure to immediately get used to working with an IDE, such as PhpStorm / NetBeans. No notepads.

A
afi13, 2015-04-16
@afi13

getjump.github.io/en-php-the-right-way
Opencart is a very simple system for simple stores, but far from the best. PHP 5.1 is outdated a long time ago, look towards PHP 5.4 - PHP 5.6. PhpStorm is a very good IDE, but it is paid, so you can look towards Aptana or NetBeans. To get acquainted with MVC, it is better to take one of the popular frameworks. For example Yii or Laravel.

G
Grigory Vasilkov, 2017-01-15
@gzhegow

1. Official site. You literally ask Google what to do and it either gives you an official site with a description of the function, or a link to stackoverflow, where your question has already been resolved. It works for the vast majority of questions, for this we love PHP very much, that the community is not sitting somewhere in a distant galaxy, but it is stupidly everywhere
2. OpenCart is made on MVC, if you do not pay attention to the standard template, which immediately destroys this MVC to hell. A lot of it was done "somehow because it didn't work out any other way", but OpenCart MVC doesn't know how to do a lot of what we would like, and to be honest, MVC itself in it could be a little simpler. The base in it is more or less suitable, except for the incomprehensible storage of trees, with the level vice versa (I did not find the reason). The main problem with OC is hard-coded controllers - that is, when you enter such and such a page, you get this layout file. Therefore, Opencart is suitable for template stores to learn from it - only the very basics can be learned, and then you start spitting.
3. Yes, it’s better to use yours, in PHP they try to find the right style every day, and often go into code construction, forgetting that you need to quickly solve the problem, and not understand that there is such a thing as a facade, a provider, and 92 more patterns from big book. Therefore, the fact that the community is everywhere is also the biggest minus of PHP, everyone is sure that his code style of his large company is the best - some shout take it ready, but you need to have a huge brain to use it, because without a liter it’s not clear why there are SO MUCH EVERYTHING. Others believe that it is possible to write everything in simple action files, making them 3000 lines long, but over time they get tired of debugging this and switch to some kind of code writing system that prompts and does a lot for a person, but even to set it up, you need a BRAIN and 4 hour video. Some slaughter and write shitty code, because they are not paid for inventing, but they are paid only to make it work, so before taking something for granted, I would recommend finding at least one more person who will not throw show-offs and send them to read - but really explain to you why this thing is used. Then yes, do it consciously.
4. There are PHP Storms different there, she can do so many things there that you can smoke more than one kilogram of cigarettes until you figure everything out. The question is, do you need a supercomputer if even a smartphone could control the spacecraft, and most importantly, that it be reliable? Well, decide for yourself.
5.1 Dreamviewer, muse, etc. are definitely not an option. You have to write so many layouts that over time you want any coding system to load instantly, and not initialize there for 10 minutes, etc. Therefore, stage one is to install the Emmet plugin and throughout the day study layout immediately trying to use it, after a day it will bounce and you can no longer write just layout. For those who are set aside, there is JADE, which allows you not to use more and less signs at all, and the code is written in python-style - instead of brackets, indents. They say this is damn convenient, so that you don’t have to constantly level the code under the ruler - if you level it wrong, it will stupidly not work. But I haven't switched to jade yet, there's still no time
5.2 Yes, MVC is a good thing, but not quite the same as in opencart. Indeed, a much cooler application template offers a javascript ExpressJS server. Request, response type, body, received data, processed, response, gone. = There everything is based on two classes request and response, the functionality is minimal and necessary. But this is more likely because Javascript is a very cool crap with its closures and an anonymizer of everything and everything that comes to mind.
6. If you have a template store without modifications - feel free to take opencart, the condition for the designer is to do everything EXACTLY AS HERE, but in the style of our company. And then you don’t really go into the code - you pull the template in a purely layout. But as soon as you set out to compress scripts, add some pages, change logic somewhere, you will sit down with opencart. It's cool in terms of - to add something that already exists, but to add something of your own is hanging up. As for the store script, a good and fast one adapted for revision is still made from scratch. The data is stored in any structure, a search engine is connected (the essence of which is to index the data for your request, and then give you a ready-made index very quickly), connect a basket script written in JS, with a backend through ajax requests (don't be afraid of buzzwords, in fact it's just a name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question