Understanding MVC on PHP with real application implementation [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Recently I have tried to read about MVC and OOP a lot. But every tutorial I found only used for displaying some static information on screen and steps without proper explanation what the code do. I have difficulty in finding a good tutorial with real application implementation such as to-do list or simple application with database.
I would appreciate if someone could explain to me how to build an application with database with MVC and PHP.
Thanks
EDIT: And I would like to know is there any way to create a working app without using framework

If you want to create your own framework or just want to develop app with following oops and MVC concepts then you have to read about the concept of MVC.
Please read
http://phpro.org/tutorials/Model-View-Controller-MVC.html - You can also
download source from http://phpro.org/downloads/mvc-0.0.4.tar.gz
http://php-html.net/tutorials/model-view-controller-in-php read and get
download link from that page.
Please let me know if this is helpful and enough to create our own small MVC Framework.
Thanks

If you want to see a real world application with MVC pattern in PHP , you should check Opencart like open source projects. If you want to know how the things are going in MVC projects, i can summarize it as :
Request goes to "Bootstrap" file of Framework than it calls "Router" to invoke methods inside controllers. These methods basically do fetch data from "Model" , processes this data and gives it to "View". By the way in nowadays world "Router" don't force you to invoke a method. You can bind a function to "Route" like Laravel does.

If you don't want to learn it through frameworks, I would recommend at least learn how to use Compposer. Find separate packages for every part of MVC and try to glue them together to make a website.
You basically need the following parts:
A database component, I would recommend a tiny ORM here (the M)
A router component (the C)
A templating engine (the V)
I write router instead of controller, because controllers can be simple callbacks, and a router component should support them.
I suggest going for a tiny project, like a small blog. You will need more component as you develop, like authentication or authorization part for blog admin. Search for the right component, and glue them together.
Also, to learn more and more, read components source code to learn how they work. It is better than writing your own version, because they have solved problems you don't even know yet.

Related

Web development strach vs framework [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
What is wrong if:
I dont use framework just use php pdo and in pages I check if user is loged in.
On frontend I use simple jquery ajax that work with JSON that I get from php pdo files and then create HTML with jquery...
I simple dont use relation in mysql...
So many developers say that my code is bad but that app builded with my code work exactly the same as code builded with laravel...
So why to use laravel or some framework when my code work great with php pdo and jquery...
Frameworks usually make things easier and faster to implement. Also, they are usually tested. So with a good framework you can save a lot of time. Also, you make the life of other developers easier, when you use common frameworks.
Furthermore, frameworks are usually maintained by a community and get updated frequently, so you have new features, without having to program them.
And some frameworks also allow plugins/extensions (usually 3rd party implementations), which you can use - again, without having to spend time implementing those.
And the last point I can think of, is that frameworks usually encourage some kind of application structure, so that you can extend your application easier in the future.
There is nothing wrong, when you write your own code, but it is just more work and takes more time and other developers might have a harder life.
Laravel Framework have the following rather than you're using, (Not in a well defined order)
Eloquent ORM
Query builder
Application logic
Reverse routing
MVC Approach
Packaging System
Restful controllers
Naming Conventions
Migrations
Composer Build
Automatic pagination
Form request and More..
Once you get started working with frameworks you don't ask this question.

What are my scripting options for a library/framework for building a web app [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am investigating building a web app.
I know systems like Twitter Bootstrap provide a great starting point for front end design but what are the options for back end, preferably PHP/mySQL but I am open to anything. I have searched around a bit but I am not sure I have the right terminology because all of my searches have brought up nothing close to what I need, so I can only assume I'm looking in the wrong places.
There are plenty of scripts out there that will create a youtube clone for example; and what I need will be similar to this but it will not be video site. My app will be geared up more towards managing and creating lists, information, tags, files ( like .doc .txt etc maybe ). I haven't actually gotten the content part worked out fully yet and I don't expect the base system to be able to handle that part necessarily but what I would like for now is if I could find some library/framework that would allow me to experiment with different content configurations.
What I need from this framework specifically is some kind of system whereby people could register and thus have a login, profile page and have variuous (private) things associated with their account ... ( again I'm not sure what 'things' yet but probably lists and possibly files of some kind). I will eventually probably need some kind of capacity to share things between members. There seems to be a library/script for everything else out there so I thought there might be something for the basis of a membership system.
So
a) can someone suggest the correct terminology I would search google for this - I was trying "portal" script and membership site but I got nowhere
b) does such a thing exist and can anyone suggest anything in particular.
One more important thing. The project is in the very early stages and has no budget so I am pretty much limited to Open Source Freeware, though I welcome any paid for solutions regardless
PS I have developed with WordPress for years now and I know I could probably squeeze this out of WordPress with a few plugins and CPT work but I really feel it might be asking too much and I'll get scaling issues earlier than I need to.
You would want to determine what language you will build the system in.
PHP/MySQL frameworks include Yii, Symphony, Zend and more. Google PHP Frameworks.
if you want to go with Ruby with a rails framework then you can look into that. Rails for Zombies is a good place to start learning Ruby On Rails.
You are referring to this as a "Portal" but I would not be searching for that. I would be looking at web applications. I build a lot of these types of applications in Yii framework with PHP. If you are familiar with wordpress, then perhaps PHP would be a better option. If you do go with PHP on a Yii framework, then consider learning how to use the Gii code generator. This will help you make tables and lists and manage records. I started with this book: http://www.amazon.com/dp/1847199585?tag=gii20f-20&camp=0&creative=0&linkCode=as1&creativeASIN=1847199585&adid=0BHF2HS6FNS82M85KJQT and it showed me everything I needed to know about the framework. It also is good if you are still quite new to PHP and Object Oriented Programming.

When can I start using a Framework (Laravel)? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I want to start by saying that I searched a lot for this exact question, but none of them satisfied my needs.
I program Php, MySQL, HTML, CSS and Javascript the 'old way', using just a text editor and building every website from scratch. I built websites from the most simple to an-almost e-commerce just by coding every piece of the application. The most advance thing I did was using some simple classes, like a database wrapper, singleton, and for the rest I always used functions.
Now, recently I signed up for a website where there are courses ( I won't say its name because I don't know if I'm allowed ) and I followed one about Laravel 3 ( I know currently its version is 4.x ), and I must admit I fell in love with it. I like it very much and I want to start using it but I'm afraid that doing so will 'dumb' me.
What I mean is that Laravel has a lot of helper functions, Eloquent structure and so on, so by using it I won't learn any more the pure Php because for everything you need there is already a built helper function.
To make a very simple example, if you want to join some tables you use Eloquent and within literally 3 second you accomplish this. If you want to log a user in, again you have an Auth class that does everything for you, even setting sessions.
This is my biggest fear, that I won't learn anything anymore because all you need is already provided, you don't have to think that much anymore.
On the other side, Laravel helps you a lot and it eases your work very much. As much as I want to start digging into it more I can't help but fear its downsides.
So, do you think I should wait and learn more traditional Php before dive into a Framework?
When is the right time to start using one?
Look at all the sites you built. Identify redundant elements. Extract them into classes and functions and build your own framework. This will allow you to build sites faster and build a library. Once you do that, there's no dumbing down. You can choose to use another or not... but you'll have yours too.
That's what I did. I have my own framework. And it ain't bad!
There are two types of developers:
users - they can use stuff and get by
actual developers - they can build stuff from scratch and give users tools
Choose which model fits your needs best.
1st category goes for quick results, are efficient and get the job done. These guys should use 3rd party frameworks and libraries.
2nd category are artists pushing themselves further with each new piece of code they build. They go for performance over turnaround time, code beauty and functionality vs. just functionality, etc... These guys feel offended by 3rd party frameworks and libraries and always roll their own. Because they can!
There's another catch. Some frameworks might have too much fat for your needs. Building more specialized solutions might actually yield way better performance than a one-size-fits-all framework. That's another perspective.
Bafta mai departe :)

php framework help [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
Ok so before anyone states the fact that the php framework question has already been answered, note that I am asking questions specifically on which framework would be best given the requirements that I am providing. I am currently in the proccess of building a large project. I will be in the future working on several medium/large and a few small projects. I am an experienced php developer and fully know OOP inside and out and have a great knowledge of mysql database so learning a system is not a problem.
Now that is out of the way down to what I am actually looking for. I have currently been using a "framework" that is not so great and was provided to me for my projects. I would like to get rid of the "framework" and actually start using an actual framework. I was thinking of building my own framework but was considering (and really leaning towards) using an already preexisting framework. I have looked at a bunch of frameworks and even played with a few of them out there. Once I choose a framework I am going to want to keep using it and not have to switch 6 months down the road so before I choose I will be doing some thorough testing before making the final decision. I would like to get some input from some users as to which ones would fit my needs best.
In a framework I am looking for the following items:
Speed - because of being larger projects I will need to keep speed in mind. I can write efficient code but if the framework is slow it really wont matter now will it :)
Authentication - I would like to be able to use some built in authentication if possible through the framework. I dont necessarily need granular permissions based on users but more or less through groups (granular permissions is not a turn off just not a requirement).
Ajax - I like to use ajax in my applications so I would like some kind of ajax implementation in the framework and personally I prefer jquery. It doesnt necessarily need to have built in ajax features but a way to kill the page with the ajax output before anything is output for efficiency.
Forms - I have seen that alot of frameworks have built in features for managing forms but just thought I would mention it here to save myself the headache.
Administration - This is possibly one of the most required features that I really need. I need to be able to create a backend to manage the site. I dont want to have to hack something together to make this work.
Api - I will be in need of an api for accessing/modifying data that I will be allowing.
Database - Built in database methods. Doesnt necessarily need to do it automatically, just give me access to be able to retrieve/update the data that is need.
These are not neccessarily requirements but more or less nice features:
I would like to be able to encase all of my data that goes with a certain item into a "module" of a sort. So that I could easily copy it to another site and have it all ready to go.
An easy to navigate structure. I would like to be able to go into controllers and not see 50 files but instead see maybe 10 folders with the files encased in the folders so that it is better separated.
I cant really think of anything else at this time but if I think of anything else I will update the post. I would really like to get feedback from people who are using any frameworks out there. If you havent messed with a framework please do not recommend it as you have no experience with it and will not know if it would suit my needs. Any help is appreciated.
EDIT:
I just wanted to edit this post to clarify some stuff. In the requirements/features that I am looking for I do not necessarily need all of the features to be built into the framework. From some of the responses it seemed as if people were thinking that all of this stuff has to be pre-ready. I more or less am looking for a framework that supports all of the features that I am looking for that is easily accomplished with the components in the framework. For example the administration, it does not have to have a default administration area but allow for me to create an administration easily from the components that I will be adding to the site.
From my own experience ( CodeIgniter , Zend Framework ), but realy all major frameworks will allow you to do everithing you asked .
Speed - CodeIgniter is the fastest i worked with , this is not the strongest feature of ZF , in fact where i work we all got to the conclusion that ZF is slow .
Auth - Zend Framework handles auth better than what i saw in other frameworks
Ajax - All major Frameworks will allow you do disable the layout/view , Zend is slightly better here , as you can have special json views.
Forms - CodeIgniter framework handles forms easyer than ZF , however all frameworks should deal with this problem with ease . Symfony needs to be mentioned here with it's form generator .
Administration - Symfony just becouse it has a nice crud form generator based on the tables you're passing ( "admin generator" how they are advertising it ) , witch will speed development quite a bit .
???
Database - ZF handles databases nicer in my opionion , however i've heard good things about Symfony too . CodeIgniter here is not that strict witch is not a good thing in my opinion .
Modular App - Building modules in ZF is realy easy , and the feature that i like most is that a module structure looks like the whole app itself ( eg. the whole app is a module ... )
Easy to navigate structure - All of them once you are used to it , however i don't like the fact that CodeIgniter keeps all it's controllers in one place , when in ZF you can add modules and separate things from one and another .
Well, I worked with several PHP frameworks in the past and there aren't many good frameworks. You could risk a look at Zend Framework
ok
ok (but not enterprise level)
ok, but dojo
complicated
no, its a framework, not an application
ok, but not really a ERM
encapsulates PDO in an ugly way (bad implemented factory pattern)
ZF is developed by Zend itself, but I wasn't really happy with that too, because it has a lot of shortcomings (cruel DBAL, complicated form handling, supports dojo instead of jQuery) and if you are used to Java/JBOSS or .NET it just sucks (only mentioning this because you are planning a big project).
If you have some time until your project needs to be deployed and if you dont need to start immediately, you could also try FLOW3 (still alpha) which is developed by the TYPO3 Team. I've played a little bit with FLOW3 and can say that it is the only PHP FW which has at least a good architecture and some good ideas/paradigms (AOP e.g.).
If I understand you in the right way you would need something like a CMS for your backend. Maybe it would be a good idea to evaluate exiting CMS's and check out if you could extend them (use the CMS as framework (TYPO3 e.g.)).
You wont find a FW that matches exactly your needs, therefore you should consider choosing a CMS/FW and customize it in the way you need it. If the project is as big as I imagine there should be enough resources for such task.

Choosing between PHP frameworks and template systems [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have a moderately simple assignment, to create a PHP/PDO site with login functionality and article retrieve/save/edit/search. No tags, nothing else.
Is this overkill to use some framework for this?
It it a good decision to use custom code + perhaps template system like Smarty for a simple site that will not grow too much?
Is there a software niche/best practices for small sites?
In a nutshell, I need logins/forms, but aren't frameworks like Zend or Cake too much for this?
I think that you can never go wrong by adding a framework to any size project. Anytime you can reuse something (and not reinvent the wheel) or leverage an existing code base to speed application development time, then do it.
Besides, you never know when your small to mid-size project suddenly grows to a large project. At least then you will have the pieces in place to grow your application and not have to start from scratch.
I'm a big fan of CodeIgniter, it would make setting up a simple website like this pretty painless. There is a fairly extensive stackoverflow answer about authentication libraries for CodeIgniter which would make login a breeze.
I would not suggest using a third party template library such as smarty. CodeIgniter has helper functions which can be used within 'views' which will allow you to do a lot of things quickly and painlessly, such as form creation.
I think using a framework is ideal for simple projects. They're quicker to set up and get going with. A framework may not be ideal if you need to fine tune how the site will run for reasons such as scalability or special requirements, or because you just don't like frameworks.
I'd suggest just using whatever parts of the Zend Framework you feel you need. Zend is very 'pick and choose' friendly.
That said, I recently used the ZF Application (MVC collection) for a two page site, just because it made things so easy. You don't need to have multiple controllers/models/view helpers to justify using a MVC framework.
Please don't user smarty. It's really unnecessary. PHP is it's own template language.
These posts on sitepoint tell the story well: #1, #2, #3
I've been using Kohana and I like it.
http://www.kohanaphp.com/
This guide got me started Kohana 101
For something that simple you can use a tiny framework like MicroMVC which comes with a equally small PDO based ActiveRecord-like database class.

Categories