If you like DNray Forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...

 

Unraveling PHP: File Structures, IDEs, and Performance Concerns

Started by dJfoiEp17, Dec 02, 2023, 12:42 AM

Previous topic - Next topic

dJfoiEp17Topic starter

I have a task:

There is a foreign website, and I've translated its pages into . Now, I want to integrate a shopping cart into the translated site. After a quick study, I've found that most popular free scripts are written in PHP.

So, it looks like I need to learn PHP! It's important to note that this project is more of a hobby for me, although it could potentially become a startup.

My limited programming background includes good knowledge of SQL, some familiarity with Perl, a basic understanding of C, and an introduction to object-oriented programming. However, I used to dislike PHP because of how it mixes code and design. But then I came across an Opencart script that uses the MVC model, which means that the messy code is organized.

However, after a brief examination of the code, I have some doubts. I'll try to express these doubts as simple questions to a PHP expert. Some questions may seem naive, but keep in mind that I only started looking into PHP three days ago and only thought about MVC a week ago.

Here are my questions:

1. Can you recommend a simple tutorial for PHP version 8.1? I'm especially interested in learning about templates and working with databases.

2. Is OpenCart a good example for studying PHP code?

3. Why does PHP have so many files? Is it because each class has a separate file, or is it just a coding style? Can I work with fewer files? It's not what I'm used to :).

4. Is there a simple IDE for PHP on Windows? Previously, I used vim on Unix for everything, but it's very inconvenient with a bunch of PHP + MVC files. Can an IDE generate a diagram of PHP object relationships similar to how SQL database schemas are drawn?

5.1 How do I create an HTML layout for PHP? Would a beginner layout designer who wants to master Dreamweaver be helpful?

5.2 Is MVC necessary for PHP at all? When running the script, hundreds of files are loaded, resulting in low performance. If my project becomes popular and attracts thousands of visitors, will I have to abandon PHP? Can I do it now?

6. Maybe PHP isn't the right choice, or what the heck is MVC? But I don't want to write a store script from scratch!

I welcome any advice, guidance, firm statements, well-founded debates, and philosophical reflections! Everything I receive will go into a completely open mind.
  •  


gramotkeas

I can help address your questions:

1. Learning PHP 8.1:
  - For learning PHP 8.1, you can start with the official PHP dоcumentation (php.net) which provides comprehensive tutorials and examples specifically tailored to the new features and improvements in version 8.1.
  - Websites like W3Schools and TutorialsPoint offer beginner-friendly tutorials and exercises for PHP, including topics related to templates and working with databases.

2. OpenCart and Studying PHP Code:
  - While OpenCart can provide insights into PHP code organization and e-commerce functionality, it might be beneficial to explore modern PHP frameworks such as Laravel, Symfony, or CodeIgniter for a more structured and contemporary approach to PHP development.

3. PHP File Organization:
  - The use of many files in PHP is often a result of the modular approach in organizing classes and functions. This promotes maintainability and reusability of the code.
  - You can certainly work with fewer files by implementing autoloading mechanisms and utilizing namespaces effectively, allowing for a more streamlined approach to file organization without sacrificing code clarity.

4. PHP IDE for Windows:
  - There are several excellent Integrated Development Environments (IDEs) for PHP on Windows, such as PhpStorm, Visual Studio Code with PHP extensions, and NetBeans. These IDEs provide robust features for managing PHP projects and can generate visual representations of object relationships, aiding in understanding and navigating complex codebases.

5.1 HTML Layout for PHP:
  - Creating an HTML layout for PHP involves combining HTML, CSS, and PHP for dynamic content generation. While tools like Dreamweaver can assist in visual design, mastering hand-coding and understanding the underlying PHP structure can provide better control and customization of the website's layout and functionality.

5.2 MVC and Performance Considerations:
  - MVC (Model-View-Controller) is a widely adopted design pattern for structuring web applications, providing separation of concerns and facilitating maintainable and scalable codebases.
  - With proper optimization techniques, PHP can handle significant traffic and scale effectively. Caching strategies and performance tuning can be implemented as your project grows, ensuring that PHP remains a robust choice for a variety of web applications.

6. Choosing the Right Solution:
  - While PHP remains a popular choice for web development, it's essential to consider other backend languages and frameworks before making a final decision. Your open-minded approach and willingness to explore various options will guide you to the right technology stack for your project.

By approaching PHP with a mindset of continuous learning and exploration, you'll be well-positioned to make informed decisions regarding the integration of a shopping cart into your translated website and potentially transforming your project into a startup.
  •  

NoelJones

I can say that OpenCart is like 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.

Yes, this is a code style that helps to localize it instantly in case of an error. It is considered good practice.

Layout for pcp should be done the same way as a regular page, only "embed" the pcp code. If you use any MVC framework, then it becomes easier to make up, just because everything is divided — you slip the data to the viewer and that's it.

From my long-standing experience (about 7 years ago, when I first took up the web), I do not advise using Dreamweaver, because it uses (or has used, and now everything is fine?) dirty markup with unnecessary elements, with unnecessary positioning in the absolute.

Perhaps low performance is due to the quality of the scripts, try to optimize.
  •  

CrisMonde

I rely on www.php.net/manual/en/index.php as my reference.

I haven't come across OpenCart, but my recommendation would be to choose a framework and build an application using it. Personally, I find Kohana3 to be the easiest and fastest to learn. While Kohana3 lacks a template engine, you can integrate an external one like Twig.

I strongly advise against deviating from the standard practice of separating classes and files – it's best to keep each class in its own file. This approach holds practical significance, especially when implementing autoload, as the system needs to locate the required class accurately.

For me, Netbeans has proven to be the most user-friendly free IDE. Generating a class diagram for languages such as PHP is quite a complex task.

MVC architecture is undoubtedly essential! It's crucial to learn to write code correctly from the outset. Systems developed without separating logic and presentation may work, but maintaining them becomes almost impossible.

The issue of low performance is somewhat exaggerated. When using autoload, numerous files are loaded. I wouldn't recommend building a scalable solution based on the assumption that "suddenly the project will take off."

While PHP may not be the most flawless language, in capable hands, I believe it's no less effective than Ruby or Python. My prior experience with Java provided me with a clear understanding of how application architecture should be crafted when I transitioned to PHP.

However, I would caution against building a store from scratch. It's advisable to start by setting up the store on a typical platform, and only consider creating a custom website if the project gains significant traction. There's no guarantee that there will ever be a need to completely rewrite the site.
  •  


If you like DNray forum, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...