I'm planning to build a single PHP web page that will contain lots of structured data in nested divs, spans, bootstrap elements etc., like:
Hardware
Notebooks
HP
Apple
Dell
Tablets
Apple
Samsung
Software
Operating Systems
Windows 10
...
The list ist really long with far more than 100 elements. The elements will change from time to time, but the structure will be the same for all elements and sub-elements.
Now, I wonder if plain HTML+CSS is the best way to code this page. As the structure of the elements is always the same, so it would probably be a good idea to use templates. However, I'm not sure if I really should set up a database and some kind of PHP framework like Slim or Laravel/Lumen in order to generate the code. After all, it's just a single page without and routing, forms, login etc. So this might be too much.
Perhaps, a templating engine like Plates could be the answer? But where should I store the data?
What would be your choice for such a use case? Single page with lots of structured data?
Any help is greatly appreciated!
Based on your subject line, I want to clarify something and then suggest a solution.
PHP Components & Composer
State of the art PHP development utilizes Composer to orchestrate component libraries. This could be in the form of a full stack framework or in the form of just a few specific component libraries that solve the problems you have.
Datastores
Your sample shows data with simple hierarchy. Certainly for ease of maintenance a datastore of some type would be helpful. A relational database or a document database will do the job. If that is what you want I'm going to suggest you use a specific ORM or at least a portion of it, and that ORM is Doctrine.
Why Doctrine? Because it supports a number of the most popular open source RDBMS, and it also allows you to use it's DBAL layer without the full ORM, if you just want to implement a few simple queries. With that said, if you have the option of using MongoDB, MongoDB collections support hierarchies very well. A great feature of Doctrine2 is that it has support for MongoDB, which differentiates it from most other PHP ORM's.
The only real reason to go to all this trouble is that you also intend to create an administration tool that will let you maintain your hierarchical data. If you don't, you could just as easily have a script that you include that has the data in PHP array form.
Templating
For templating, my suggestion is that you use Twig. As part of the Symfony components, Twig is both self contained and part of the Symfony full stack framework. It's robust and well designed, and has numerous features (although to be fair, Laravel's Blade has similar features in most cases) and includes support for ESI which could be a great feature for a relatively static page like the one you describe.
Templating in twig, vs writing PHP code to do the same, lets you focus on your markup and avoid introducing a lot of PHP code that will turn your view code into spaghetti.
Components
The important thing is that you can simply use the few components you need to support your application, and you certainly don't need either Laravel or Symfony. Since Symfony began its life as components (and was the foundation for the Laravel project in fact) I'd push you towards the Symfony components, although at the end of the day, you could also utilize parts of Laravel (Blade, Eloquent) in the same way that I'm advocating you use portions of Symfony. Symfony simply is the community and stack I prefer, and has a longer history of being used on a component basis in other projects.
Try out the new minimal Symfony4
Last but not least, the newest version of Symfony (Symfony 4) is really worth looking at for a number of reasons. It essentially is now a micro framework, that comes with the bare minimum of components. They advertise it as 70% smaller than v3.
What differentiates this release is the innovation of Symfony flex with recipes and Composer integration. It is now built to automate a lot of the things that you might otherwise have had to figure out on your own for putting these components together into an application.
Take a look at it and see if it might help you get your application built with minimal components and minimal time spent having to learn how to make things work together.
In summary, I'd suggest you consider:
Symfony Components (You might want a few more depending on your
final solution).
Doctrine2
Twig
Symfony4
Related
I'm a beginner php developer who is trying to build a social network for my school students. Knowing that the school has over 1000 students who are already active, I must have a plan of expanding / scale the code that I write.
Earlier it was just the LAMP Stack, now the modern web development is way more than that as I see, I'm truly kind of lost in what technologies to use and how to incorporate them to build a scalable app. I'm hoping to divide this application into 3 layers.
Application layer (phalcon,reddis,apache,php)[mvc api centric]
Database layer(mysql)
UI layer - (html/css/js/)
This is where i need help, is this design approach good for a scalable app ? where can i improve ? any explanations, links for further reading will be a highly appreciated.
Welcome to SO. I cannot think of a particular reference guide to direct you to (although the PHP manual is a good place if you end up stuck with how to do something specific). I would suggest reading a bit of several results when you search "Getting started with MVC in PHP" and noting what they agree on. That said, take a look at what I say below (and then ignore it as much as you please ;) ).
Firstly, you are wiser than many in sorting out a scalable design before launching into the project...
I'm excited to see Phalcon in your list there already. However, as DevDonkey suggested, start with something simpler first (Phalcon is very powerful but to really get to grips with it you need a good grasp of PHP, particularly object-orientated programming).
If you are completely new to PHP...
... try building a small app (products table, view/add/edit/delete functionality) and learn the beginnings of the language that way, as this answer suggests. Things will go wrong and you'll discover lots of headaches when you want to change one feature and it affects everything else but that will help you to understand the importance of...
MVC design
From your question I can see you have at least heard of this. This is really where the layers of your application lie:
Model - interactions with the database (retrieving/editing data) are handled through this. So you could have a MYSQL database and then your models provide a nice interface to interact with the data (generally you have one model for each table).
View - this is the last layer, what the user sees. So you will make use of your html/css/js knowledge here. On this topic, unless you really want to do your own css consider using a CSS Framework such as Bootstrap. It will really help speed up making your site look good and there are loads of free templates out there to use with it.
Controller - this is the application logic. The controllers request/manipulate data through the models and then decide what to send to the views for rendering.
Use a framework?
Using a good framework can make your application more reliable and quicker to build. But using a framework without understanding it will be frustrating, slow and possibly result in worse code than if you didn't use one to begin with (as you employ hacks to get around the pieces of the framework you don't understand). My current favourite is Phalcon but as a relative beginner to PHP I would suggest something more like CakePHP although both Laravel and Symfony are also popular.
Summary
Start small, learn, test ideas out and then build up to a bigger project.
Get comfortable using PHP (including OOP style) before using a framework.
Use an MVC framework
The layers you laid out in your question are good, but I would split it slightly differently (considering that MVC is the 3 layers)
Application Layer - controllers, written in PHP, handles logic/manipulation, often the biggest layer
Database Layer - models, written in PHP, you will also need a database which could be in your favourite database language - MySQL ;)
UI Layer - views, possibly written in PHP (depending on the framework) but also HTML, CSS and JS as well as well as a templating language if you wish (e.g. Twig or Volt), essentially a way to make the response from the controller nice for a human
First Project (for CakePHP)
This blog tutorial is a good place to start if you decide to use CakePHP.
Getting started with Phalcon
Phalcon is more powerful/verstile, but to get started with it I feel you have to be a better PHP developer than you do to get started with something like CakePHP. Take your time to understand each new concept with Phalcon, particularly Dependency Injection.
Even having used CakePHP for the past 2 years and being familiar with MVC patterns and PHP, I still worked my way through all 7 of the tutorials in Phalcon.
Having said this, my favourite thing about Phalcon is that it is highly decoupled - so it is fairly easy (after a while) to replace bits of it with your own extensions if it doesn't quite do what you want.
Note about Phalcon: It is not as popular as many other frameworks (although popularity is growing) and so you may have to spend some time digging around when you get stuck. However, the docs are improving all the time and the forum is very active. Unfortunately the number answering questions about it on StackOverflow is still small compared to many other frameworks.
I am starting with PHP DATAMAPPER AND ORM.. I am completely new with it. Though I got knowledge about through google. It really found interesting.
I have few doubts with it.
Can I use Doctrine 2 library/ORM with my Core PHP Project. Or it is only for framework like CodeIgnitor, Zend or else.
Is it really helpful for fast development. Or it may get expanded after some extent.
Can I have any example/ esp. tutorial where I can implement it with CORE PROJECT means some blog or else.
I checked with phpdatamapper.com. I found it easy but it was quite old as not updated since last 3 years. Is it good to implement that ? Any source implement that.
I would really be pleased having source/implementation (simply on blog) on github or else somewhere. Please
ORM like doctrine can be used with every project, it does not need any framework. You can include them in your projects with composer.
About Doctrine, you can use two things depending on what you want to do :
Doctrine\ORM and its whole bundle. It brings you the whole functionality, with its ORM and other cool stufs. If you want to use it, you have to put that line on your composer.json file :
{"require":
{"doctrine/orm": "2.3.2"}
}
Doctrine\DBAL. It is only a abstraction layer without the ORM functionality. It is here to bring you more functionalities to PDO, and build queries without taking care of your data base engine. As it has no ORM it is faster to execute but it does not bring any conception facility.
If I introduce you to these two tools it is because you will have a choice to make. If you want a simple blog site, Doctrine\DBAL is what you want as it will bring no performance issue.
If you want a bigger application with a full architecture, you need Doctrine\ORM as it will help you to build and keep your data base safe.
About tutorials, the documentation is built like one so I think you can get started here for the ORM and here for Doctrine\DBAL
Blockquote
Edited:
http://blog.fedecarg.com/2008/06/28/a-modular-approach-to-web-development/
The above approach is what I'm looking for. So are there php frameworks available which will allow me to create modular structure like above for my code ?
Edited:
Blockquote
I would like to know which is the current best php framework which is 100% modular like joomla component architecture.
In joomla all you have to do is upload a set of files under the "components" directory and you can add "any" kind of complex functionality to joomla.
I want to develop php applications from scratch and I want all of my applications to have the same ease of joomla's component architecture. So Im currently looking for a php framework.
So which is the best way to go about if I want to do the above ?
Should I choose a php framework like codeignitor or zend etc ? but you see, even if is use them, Suppose if I have to create a new function I have to upload files to atleast 3 directories i.e controller, model and view. But you see in joomla all I have to do is upload all the files of course suitably structured into just a single directory called "components" and the rest is taken care of automatically
So what is the best way to go forward ?
Shanthi
Joomla is a CMS system AFAIK so you cant really compare a PHP framework to it.
In terms of modularity Zend Framework has an excellent excellent, simple to implement module structure.
You sat that to add complex functionality to joomla you upload files in the correct structure and joomla does it for you, well as long as you create your module files in the right structure for ZF it will work too......
Your question is same as my question. but it was for 4 months ago.
I tried to find out how can i create such modular system. After some searching I understood that we should have a single directory like 'components' as you said, and put every data of modules in it. but how we should use them ?. Easy !. just create an handler (php file) that control your installation, uninstalling, positioning, settings. In fact i just solve 3 of them. positioning is so hard i think so, i never do it till now.
if you want an example of my explanation, just tell me to create it. I'll send it for you. :)
well i think you are comparing apples to exotic devil fruits or something.
you are adding modules to a cms and exepct the same from a famework.
it doesnt work like this.
the mvc structure you are talking about (model - view - controller) makes a lot of sense and helps you to keep your code organised and to keep up good class coherency.
its a design pattern which has evolved to a de facto standard and has been adopted by almost every framework.
zend framework is probably the best way to go for you.
its layouting engine and stuff is not as fast as one could wish, but it features execellent modularity. you can even partly overload core classes to suit your needs in your "module".
only abstract classes dont work (how should they?), thats why they are almonst never used.
if you really really wanna go with a very flexible excellent system and performance is not the most important point for you, you should get going with magento, which takes the modularity and flexibility even to a higher level by adding an xml structure to zend framework that allows you to organice all your pages, manage your dependencies, rewrite your model componenents etc.
but be a aware that the more you want the more performance you will loose. my personal fav from the frameworks out there is codeigniter, but i designed my own for my needs...
I agree that there is a difference as Joomla et al as CMS's and therefore come in at a higher level of functionality than a framework, but of course with less flexibility.
However you might want to explore Symfony 2 and Lithium (Cake 3?). Both are designed to only use PHP 5.3 and greater and both use the namespace functionality in PHP. I have done less with Lithium but certainly in Symfony 2 everything (well nearly everything is a plugin making the framework modular and much easier to manage.
However you will never be able to compare the two Framework/CMS in exactly the same way as they are both built and designed for different purposes and with varying constraints.
N.B. Neither Symfony 2 or Lithium are production ready at present. Symfony is aiming at March 2011, not clear on Lithium's 1 dot oh date
[edit]
A number of answers here plump for Zend. What needs to be clear is that there are two types of framework (yes ok lot's and lot's) but being simplistic there are Full Stack and Glue.
Glue frameworks like Zend tend to be free and easy allowing you to use some parts and not others as you wish. So although nominally MVC you can easily implement Zend with V and C but not use M. You can write all your database calls manually in the controller etc.
Full Stack such as Symfony mean you pretty well use all of whether you like it or not. On the data side you use and ORM, Doctrine or Propel and a large amount of the framework is controlled from configuration files in YAML/XML. In this respect Symfony is very like Ruby et al. Please note this is not a recommendation or criticism of either.
Joomla in my opinion is gluey (but not a framework) but hey why use something that is 90% built and then rewrite 75% of it? Oh yes because the customer asks and your boss is unaware of the problems, i remember now.
I have ready numerous posts here on SO about framework1 vs framework2 however it seems to be alot of personal opinions that are one sided. Based on the following can someone tell me which framework would be ideal for my needs?
Build a rich featured API where other sites and devices can use the API to use website features and access it's content.
RSS Feeds with both XML and JSON for jQuery interaction.
Ability to use layouts / templates that are customizable.
Use of plugins so that I do not need to duplicate code.
Database querying with relationships.
GREAT documentation.
Actively supported.
Doesn't REQUIRE command line access.
Easy to manage file uploads and move the files around so only certain users can download them.
Customizable access level so users can have different access levels depending on which project/section they are viewing.
Low overhead usage.
SEO URLS that do not require the '/view','/edit','/add' in the urls (depending on which action you want to do.)
Support for jQuery
There have been a few frameworks I have seen that support some of these but not all. I am currently using CakePHP for one project but do not think it would fit my needs as the database querying can get horrendous. I have heard a little bit about CodeIgnitor however it doesn't seem to easily use templating (maybe I just misunderstood what I read).
If you could tell me which framework you think would be ideal for these needs and why that would be very helpful!
I'll just spamvertize my little framework overview table here. The simple table answers a few of your technical points:
http://matrix.include-once.org/framework/simple
Use the detail/feature view to cherrypick your options.
RSS isn't a standard feature even with the big frameworks, use a PEAR library
templates: all frameworks use them
plugins: depends on your concept of plugins, most frameworks are extensible though
look for "ORM"
GREAT documentation: that would limit you to codeigniter or cakephp
Doesn't REQUIRE command line access: except symfony+cake, few do
file uploads: this isn't a standard feature, but I'd just mix and match a library
Customizable access level: practically all frameworks come with a permission system
Support for jQuery: this is surprising. Prototype seems to be very strong, only half the frameworks use jQuery by default
CakePHP database querying doesn't have to be horrendous. (Though, I remember my first few projects were definitely hard on the database)
With the right optimization, normalization/de-normalization of your data, and a few tweaks here and there (persistent models comes to mind), you can accomplish everything you've inquired about with CakePHP, and keep your database load to a minimum.
That said, if you truly want to move to something else, I'd go with Zend Framework.
Symfony is bloated, (and yes, fanboys, this is still true).
Codeigniter is super lightweight, but you're going to be doing a LOT more work to accomplish your listed requirements. I've spun up two codeigniter applications, both relatively simple, and both took twice the work / twice the amount of new code than if I had gone with say, CakePHP.
A lot of religious fanaticism floating around when you talk about frameworks. But take a look at the documentation of Fat-Free Framework. It just might catch your fancy and requirements.
Before I answer, let me qualify that I'm certified on Zend, a frequent user of CodeIgniter, and daily user (and hater) of Symfony.
Zend's setup, especially if you're doing a small-medium sized site can be ugly. Especially using the data mapper strategy, you're talking a thousand or more lines of codes just for the model setup. CodeIgniter is much better setup-wise, but still not insignificant.
Command-line free --essentially-- knocks out Zend. It's doable, but not fun (see thousand lines of code, above) Built-in user auth isn't nearly as good on CodeIgniter as Zend, perhaps that's a serious knock....definitely no templating there. Symfony is flat-out done because of the addition of /view /edit, etc.
Hate to break it to you, but it seems that many users of all these frameworks are not native English speakers. Forget about Symfony, seems entirely eastern-European based. I'd hate to be a new-to-php user of Zend Framework with all the competing tuts with their assumptions of some semi-complex concepts. There's a reason that Zend's training is expensive and full.... Again, CodeIgniter is not horrible, but still can be frustrating.
Simply because of our extensive use of Jquery and desire to avoid a ton of hack-around, my company has dumped the frameworks altogether. Now setup is purposeful, not for a framework...just build a DAL, assemble classes, build views, and done. Established functions are re-purposed as "plugins" that we actually know and understand. Most interaction is Jquery based Ajax (sometimes XAJAX) which really doesn't take advantage of the frameworks anyway--and fights tooth and nail with Symfony. For those who argue that frameworks force MVC, I have a VP of Development who does that just fine, thank you. Perhaps it's not the right answer for you, but we're glad we went this route. It's saved weeks worth of documentation-hunting.
My team have to maintain a large php application that was very poorly written. It is a mix of html, javascript and SQL on top of a large poorly designed database (ex. it has a table with few hundreds of columns). The only advantage of the codebase is that it works.
We are constantly bug fixing and rewriting parts of it.
I would like to give a structure to the rewrites we do, so I've though about integrating an mvc framework in to the codebase. Could you suggest any good framework for environment?
Here is a list of things that the I would expect from such framework:
The API must be very stable. We can't afford to rewrite the code on each release.
Custom session management or at least working on standard $_SESSION[] (To be able to talk with old code).
Custom authentication.
Using the raw SQL should be well supported (The database is hard to represent in terms of objects).
It shouldn't assume that I will have a table per controller.
I suggest Zend Framework for this purpose because it is a glue framework. With ZF you are not forced into the harness of how the framework expects you to work with it. You can pick what you want and gradually replace your legacy code with code from ZF. It also supports all the things you mentioned.
In addition, I suggest to run the various QA Tools found at phpqatools.org to support you in debugging and refactoring.
Framework comparisons
http://www.phpframeworks.com/
http://php-frameworks.net/
I'm echoing Zend just to list how it fits your specific requirements:
The API must be very stable. We can't afford to rewrite the code on each release.
As mentioned, the API tends to be stable between minor releases. Major releases with changes shouldn't be hard to integrate.
Custom session management or at least working on standard $_SESSION[] (To be able to talk with old code).
Zend_Session does exactly what you want. The default session store is $_SESSION to which Zend adds a namespace concept. Your existing code should be fine, and any new code can use the Zend object to ensure there are no variable name overlaps.
Custom authentication.
Zend_Auth has a few authentication backends, but it is designed to allow you to implement your own auth.
Using the raw SQL should be well supported (The database is hard to represent in terms of objects).
Zend_DB implements the table gateway pattern which will allow you to access the data via object; however, you can also just use SQL directly and get the results as arrays.
It shouldn't assume that I will have a table per controller.
Zend_Controller and the rest of Zend's MVC implementation make no assumptions about the Model, leaving that completely up to you. I'm sure some people don't like that, but it is the one area of MVC design that varies greatly from project to project - so that's left completely to the developer. You could extend some of the DB classes, or just use the existing DB access code.
That's an example of the pick-and-choose mentality of the Zend Framework. You really can use any of the library by itself. That should work well with your project. For example, you could use Zend_View without the rest of the MVC classes just to move your presentation into templates. Or just use Zend_Auth to replace the existing Auth system. With Zend you can slowly move your project into a more structured state, little by little.