Is AJAX enough? Should I learn a PHP framework? [closed] - php

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I started learning programming 4 months ago. So far I already know some javascript(and jquery), php, ajax html and CSS. Yesterday I saw for the first time in one of the stack forums a question about PHP frameworks (zend, codeigniter...etc).
I hope these questions are not very stupid, because I am a beginner so I don't know much about this world yet, but my questions are:
1- Do I need to learn how to use a php framework if I just one to build ONE website?
2- Do websites nowadays rely more on AJAX + some php OR just PHP + some javascript?
3- How long does it take to learn and master a php framework like zend?

1) You don't need to learn a PHP framework, and in fact if it's the first website you've ever built I'd suggest building it without a framework just to get a feel for how PHP works when building a site. This way you understand things like database connections, session management, etc. that is often done behind the scenes with frameworks. Then later on try building it with a framework to get an idea for the design patterns and other features that a framework has built-in to avoid code repetition, security holes, etc.
2) I don't know what the difference between AJAX + some PHP and just PHP + some javascript. AJAX is a part of Javascript, it isn't a separate technology on its own.
Some websites use a lot of AJAX, some don't. It really depends on what you want the website to do and your particular design: AJAX can provide a smoother feel to the site, but can have complications when it comes to things like back buttons and bookmarks.
3) Depends on what you're doing with the framework: if you're only using 10% of the features you certainly won't become a master in any amount of time. It also depends on the complexity of the framework: I haven't used Zend but I know that the more complex the framework, the longer it will take you to learn it.

Learn as many thing as you can. PHP is a good start, becouse it's very popular and easy to learn and use. There are many great frameworks written in PHP (Symfony, Zend, Kohana, etc.). However, it's not a nice, well designed language at all. Keep it in mind, don't stop at php, learn it then make progress.
b) You will be able to build a large variety of sites with PHP+JS+HTML
ps.: AJAX is a technology, and as a knowledge, it doesn't worth so much as is.

Ajax is just a technology to call server side scripts from Javascript. The server side script being PHP. So, if you intend to use Ajax, you need to know PHP.
As for PHP frameworks, its good to build a few website from scratch using PHP to get a better understanding, but eventually, its better to adopt frameworks. Frameworks implement a lot of the functions and methods you need. No point re-inventing the wheel.

The answers to your questions are very subjective, but what I suggest is:
No you should not learn a framework to build one website. Just go and build it in any way you can. Frameworks usually carry a lot of additional concepts and methodologies. You will have to invest quite some time to understand how they work, but it will be really hard to understand why they work that way. Doing a website is a great experience, so just go and build something.
Lets say websites mostly rely on HTML / PHP / JavaScript. Ajax is just an additional capability, which you are already focusing too much. It's great that you know what Ajax does, but you should concentrate more on the essential things, like number one.
Lets say it takes two years of constant interest in the field. So at first you learn the syntax of PHP, then you start to know how HTTP works, then you experiment with HTML and JavaScript/jQuery/Ajax a bit more, then you try a Framework. You keep trying until you become a master. Zend Framework is one of the most comprehensive, so it will take a while to study how it works and all the related technologies it brings with it.
My final advice is to stay focused, build something, see what challenges it brings, solve those challenges and eventually become a master. Good Luck!

Question One - The short answer is: it depends on the type of site you're building. The frameworks you're talking about were built to streamline web application development, which make extensive use of databases and object-oriented principles. If you're planning on building a site with mostly static content, I wouldn't bother learning a framework just yet.
Question Two - Again, it depends on the site. The concept of AJAX has many applications, but most sites employ it to make a site more interactive (e.g. not refreshing the page to load new content). For sites with primarily static content, AJAX has fewer uses.
Question Three - It can take a while to 'master' a framework. I'm not that familiar with the ones you mentioned, but learning a framework is less about understanding it's syntax/quirks and more about learning how to approach a problem their way. Again, it depends on what you're doing.

Related

My Content Management System [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 6 years ago.
Improve this question
I intend to develop a Content Management System (CMS) like shown in the figure below;
Figure: Intended CMS design
Is it possible to completely develop it using PHP's standard library?
Do I need to use a PHP web framework? If so, why and what framework is ideal?
I hope to use MySQL as backend.
I hope to use below technologies as front end;
HTML5 and CSS3 - hard code by myself (Is there any framework or something make it easy? I heard something lesscss.org)
jQuery - to make HTML elements functional
Ajax - to avoid page refreshing
Bootstrap - to make my CMS responsive
Are there any technologies I do use, or any suggestions?
I prefer to improve my HTML, CSS, PHP and other technologies by learning and hard coding. So I hope not to use CMS like
joomla, WordPress, etc. Am I right?
Please note: I've already searched Google extensively before I put my questions here. But I am unable to confirm what I do next. Your comments are appreciated.
Your questions really look well researched and I think everybody with the intention of building a custom-made CMS has come to this point where they ask themselves these fundamental questions (in other words: good questions!). Now to some answers:
1) Yes it is possible.
2) Although building a CMS in pure, native, hard-coded PHP is possible, I wouldn't recommend it for production. You could do it, and you would largely profit from the experience, but there are many little problems (like Routing / User-Management / Authentication / Communicating with Database / Form-Building (like in your screenshot) / etc.) that are already solved by a good Framework.
Also as you are a beginner, you are naturally overwhelmed by the problems and decisions you have to solve/make. This is also a good point why a framework would be a good starter. Although some solutions are sometimes a little too opinionated, they still give you a good structure to start with and most of the times follow best practices of our industry.
Which framework is the most ideal for your project, you'll have to decide on your own, based on your requirements, but some common ones are:
Symfony (probably the most known and most used php-framework, but also very abstract / I would recommend this on a really big project, where you work in a team and you are aiming for flexible maintainability)
Laravel (excerpt from their website: An amazing ORM, painless routing, powerful queue library, and simple authentication give you the tools you need for modern, maintainable PHP.)
Silex (the little brother of Symfony, info from their website: Silex is a PHP microframework for PHP. It is built on the shoulders of Symfony2 and Pimple and also inspired by sinatra.)
FatFreeFramework (from their website: A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust web applications - fast!)
As I used Silex myself many times and also when I began with best-practice PHP, I recommend to start with it, if you decide to write your own CMS. I pretty fast did some Management-CMS similar to your screenshot with it (with their Form-Builder) and was happy with the result.
3) Again this is up to you. For the backend you will probably use MySQL anyway, if you just need a database. In the frontend using HTML5/CSS you could try jQuery and Bootstrap (and then here their less or sass implementation).
If you really don't have too much logic for your JavaScript, you could also try to just use native JS, without jQuery. This way you will also learn more about the language and have less vendor-dependencies the user has to download.
4) If you are really up to learning a lot, then yes, you should probably hand-code everything yourself. This way you also have total control of what code gets delivered to your user. That's a problem with most common CMS: they pollute your code through some other plugins or something and you quickly loose control over your output.
But if you need to be fast there are also CMS that address this issue by giving you total control over your output and giving you creative freedom, like MODX does.
In the end it is up to you and especially the needs of your project. If it's a simple website and you conveniently want to edit the content and also have some starter-help, then I recommend to use a CMS.
If you really want to learn about all this stuff and you have some special needs, then go on and code your custom-coded application. In any way: good luck! :)

PHP code design, structure, pattern ..? [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 4 years ago.
Improve this question
I want to get some input from experienced PHP developers on how to structure code.
I feel my applications soon get "dirty" and unorganized.
Should I start coding in OO? Should I start using MVC? What about design patterns? What other options are there? How can I organize and structure my application code better (beyond proper indentation and naming)?
Links to resources are welcomed :)
If I decide to start coding using MVC? Should I use any frameworks or just hand code everything?
What is your suggestion.
Instead of worrying about creating something from scratch, I would start by using a framework and extend it with your own widgets. Zend Framework is excellent and has a massive community of support: http://framework.zend.com/
Otherwise, the best book so far I've found about PHP design is called 'Advanced PHP Programming' by George Schlossnagle. It explains patterns and design efficiently better than anywhere else I've seen.
As per comments below, I definitely don't mean to say that you should only learn a framework. It's never good to learn only a framework, but you can learn coding techniques through other peoples' code, like in frameworks/libraries/etc. Attack your learning through every source available (forums, books, code resources) and make an educated decision as to the approach you should be using when taking on a new project.
My suggestion : use the Symfony framework at least once, the tutorial will teach you most of the best practices you need to know, and let you organize your code in a good way.
Well for me JAVA is one of the best ways to really see how OOP is done. The way it's done in php is kind of lame. I've seen a couple of well structured maven based projects and I say "WOW" every time I see them again. You should start using the MVC model of coding as it'll make things easy for you to monitor - Controller = pages's logic, Model = page's (sql) data, Viewer = page's template.
Best you could see what I'm talking about at this site http://php-html.net/tutorials/model-view-controller-in-php/ .
Take it one step at a time. Download Smarty and get familiar with it. This should give you wonderful warm fuzzy feelings about separation of concerns, and give you some insights into other things to look into.
There is no silver bullet.
It doesn't matter how you start to plan, what matters is that you plan. Start with something basic like MVC and try to find reasons why your app shouldn't be made that way. If you can't find reasons, think about what frameworks might have features you are going to need.
If MVC is going to just add a lot of extra work. Such as if you are going to be doing a lot of complex AJAX or serious multi-level caching, or other reasons. Figure out what kind of system might save you time.
With heavy caching, sometimes basing the whole structure around a cache system can work. Tap into cached strings as templates and you can now alter pre-cached items. Useful for pages that are assembled on the fly iGoogle style.
The solution will come from the problem.
I would suggest you try to work with some popular framework. This way you can read clean code and form your style. 'Yii framework' is good enogh as for me. Offcourse, it will be useful to read about design patterns not only for your php skill, but for programming skill in general.

What to do after learning basic PHP? [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 7 years ago.
Improve this question
I have learned extremely basic PHP (I think so) using Lynda Tutorial. After that, I feel, I got some grip on that language. My ambition is to become a web developer! After some googling, I planned to learn some more advanced and practical php by using websites like PHPSCripts, Webapps etc..
But, now I'm in a confusion! After my studies, when I seek for a web developer position & got selected, how will I work, by just knowing some language basics?
Can you guys help me to become a good web developer, what will I have to learn & how to learn?
Also, can I get the steps to do a practical PHP project.
As a web developer it is important to have client and server side skills. But there are few web developers which are excellent at both... But knowing the basics and where to look for info is definitely a good starting point.
I would recommend to work through the following list(s) in the order presented. If you feel comfortable with a topic, move one. Even though that in reality you will often have to go back and forth during the learning process...
Client Side
HTML / XHTML
CSS
a JavaScript Library (e.g. jQuery, prototype/scriptaculos, etc.)
Server Side - Infrastructure
familiarize yourself with shell scripting if working on Linux (e.g. bash, etc.)
Webserver (e.g. Apache)
PHP Server
Databases (e.g. MySQL, PosgreSQL, etc.)
Server Side - Programming
PHP
SQL
Advanced Topics
After getting familiar with the basics...
AJAX (this is placed here because it is a client/server topic, not because it is advanced...)
Object Oriented Programming (OOP)
Security issues
Source Control Management (SCM) -> (e.g. git, etc.)
Model View Controller (MVC) software architecture
PHP Frameworks (Zend Framework, Symphony, CakePHP, Agavi)
Unit Testing (e.g. PHPUnit)
Object Relational Mapper (ORM) for PHP (doctrine, Propel)
Usually this keeps you busy for a while. At least it kept and still keeps me busy... ;)
Here are few suggestions:
Read these advanced/practical php articles on phpro.org
Learn the basics of OOP
Familiarize yourself with php frameworks and CMS
Familiarize yourself with HTML/CSS/Javascript
Try to make clones of other websites
Try to volunteer in open source projects, you may get started at:
openhatch
sourceforge
Im my opinion, A good webdeveloper MUST know:
HTML
CSS
JavaScript
After this, it's important to know:
Jquery
XHTML
Crossbrowsing (diferences of IE X Firefox x Chrome, etc)
Rationale:
HTML: it's the base of web.
CSS: in 2010, it's the base of web.
JavaScript: only the basic, to understand jquery after.
Jquery: you can solve a lot of problems quickly and it's large used.
XHTML: because your page may broke in modern browsers, if has a <br>, not a <br/>
Crossbrowsing: there is more than one browser in the world.
Just keep on practising. You will likely need solid HTML / CSS skills as well as PHP since the two go hand-in-hand - it's also useful to learn MySQL. Spend lots of time going through the tutorials on the excellent tizag.com as well as Lynda.
Once you're comfortable with all that and you're ready to move onto something more advanced, it's worth looking into Wordpress customisations and plugin development - that has the advantage of being pretty easy to use, with an awesome support community, and a whole bunch of mature code that you can look through yourself to get more familiar with how the language is used in the real world.
After that, try a framework like CodeIgniter or CakePHP - these are awesome for your productivity but do make sure you're comfortable with the basics first as the learning curve can be pretty steep and you want to reduce frustration as much as you can. :-) Learning design patterns will also be helpful at this stage.
One thing that will always be important to you, your users, your applications, and your potential employers is code security. I can't stress this enough. As soon as you put an application into real-world use, you have a moral and professional obligation to make that application secure. http://www.addedbytes.com/writing-secure-php/ <- read, digest, read other guides. Security is the single most important thing that a PHP developer can learn.
Above all, have fun! The best developers tend to be the ones that get genuine enjoyment out of what they're doing. You might find yourself eventually leaning in a different direction and using completely different technologies, so always keep your eyes open and be prepared to learn new things even if they don't necessarily 'fit' your current skillset. Also the more general knowledge you have about programming patterns, the better you will become in individual languages. Remember that it's an organic process so you will need to let it develop naturally - but help it along by exposing yourself to as much as possible (foreign language teachers call this 'immersion' :-) )
Regarding PHP
Make a small project using PHP, so you know that you know.
Learn a (MVC) framework like CakePHP or Agavi.
Read this SO answer.
Regarding Web Development in General
Know about CSS, XML, XHTML, XSLT, W3C validation, HTML5, JavaScript, AJAX (and most other acronyms you come across).
You will find there are various libraries which make your life easy, use them. And there will be one browser that will make your life difficult, but you will have do deal with it.
A solid web developer needs an understanding of HTML, CSS, JavaScript, and the server-side scripting language of her choice. But still more important is a solid foundation in programming. You don't have to be an expert computer scientist, but you need to understand how to structure a program and how to solve problems in a sensible way.
Most professional web development involves database access of some sort. Teach yourself SQL, and use a real SQL -- not Access -- for the effort. You can run MySQL or Postgres on a laptop these days, and it's free.
Learn to design databases well. Learn about normal forms, and indexes, and so forth. The time you spend on that will pay off in spades.
Take a while to study up on security. Look at the security bugs that have afflicted high-profile projects and sites. (Hint: they're pretty much mostly about trusting untrustworthy data, or else relying on old out-of-date infrastructure, but the consequences include site defacement and the compromise of valuable information.)
And then, take on a charity project somewhere. You won't get turned down, and you'll cut your teeth, so to speak. Just make sure you're not storing social security numbers or something crazy like that, because charity workers are often vulnerable to social engineering attacks.
the very very first thig to do is to learn Object Orientated Programming (if you haven't).. then you might want to start learning the MVC pattern... and then you must decide either you star using frameworks (like cakePHP, Symphony,Zend) or you prefer using CMS (like joomla or wordpress)... on the process you might also want to learn javascript using a framework (mootools, jquery or prototype)...
Edited: i forgot about databases and sql!! wow.. there's a lot to learn!
The only way to become a good programmer on a certain platform, is to study something more than just tutorials. Read a book, at least. Then the rest comes with practice.
A good way is to also learn a specific platform (depending on what they work with). Some work with Wordpress, so once you know basic PHP and how to use it with databases, and how to work with databases, you would be able to quickly make some basic information websites. Others use Joomla, Drupal, DLE, to quickly build websites, without having to hurt their heads with full backend and frontend architecture. If you need a more general approach, to be able to make more specific web applications, use frameworks like Zend, CakePHP, Symfony, CodeIgniter.
Also, besides knowledge of PHP, to build a small website by yourself, you will also need to know HTML, JavaScript (with AJAX, possibly a framework like jQuery), SQL.
And last but not least, you will need to learn how to protect the site against XSS, SQL Injection and other security threats.
Learn Object Orientated Programming (OOP for short).
Watching any programming tutorial is different than watching any movie. You need to have practice and have experiments form different angle of codes. Prentice and research is only way to get into the deep of any language. If you think you have well understanding about php then try to make some small application like phonebook which have database connection. After that you can move for any frame work like laravel, cakephp. But I always recommend to do at least one small project with raw php before move for any framework because when you come from raw php you will start loving working with frameworks otherwise you will may feel boring to learn again something new as my point of view.

Is it possible to learn Zend framework without learning PHP first? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
this is maybe a silly question but I am really wondering if it is possible to use a MVC framework such as Zend without learning the language first? Thank you for your help!
You can't learn Zend Framework without learning PHP. That you might have guessed.
After, you don't need to have a degree in PHP to learn Zend Framework.
You can learn them both together.
Short answer: No.
Long answer: A framework serves to speed up development, by giving you a set of tools to handle mundane and repetitive tasks. Some frameworks also enforce a specific programming model, but their primary task is always helping you write faster and cleaner code.
Having said that, it becomes quite obvious that anyone thinking of using such a framework, first needs to understand (globally) the language it's written in. You don't have to know every available function by memory (who does?), but you will need to know the basics at least. As I said, a framework speeds up your development. It can never replace it.
If you write poor code without a framework, expect to write poor code with a framework.
If you can't code at all without a framework, then you won't be able to code with one either.
It is possible to lean MVC in general without knowing a programming language. Learning a specific framework will mean learning the language in which it's written. So, yes, it is possible to start learning Zend Framework without knowing about PHP, but be prepared to learn PHP on the way.
I would say YES it is possible, but provided you have experience in other languages or framework. However you cant really go far, and you probably learn PHP along the way in exploring the framework. From scratch will be kind of tough though.
To add:
I was learning Drupal without actually learning PHP prior. But in the process, I kind of figured out bits and pieces of PHP as I've knowledge in other languages.
Sure you can. You might find it slightly more difficult though if you're not familiar with the language. It depends on how much programming/language experience you've had previously. PHP is a relatively straightforward language to pick up but obviously if you've not done development before with something with similar constructs and syntactical similarities, then you're going to struggle.
Zend can be a complex beast however, and I'd recommend at least playing around with PHP to start with so you get an idea of how the language works, before you dive head first into the framework.
I think you'll struggle like hell, even if you do manage it. Frameworks are tools that encourage good programming standards and give you access to libraries for which you can call functions into your applications (to avoid writing everything or hard coding). If something breaks you may have to manually fix something, what are you going to do if you can't program to fix problems that occur within the framework (hire someone?)?
I suggest you go to the php website and buy a book on the language to get your feet wet. I suggest starting with the essentials of any language: variables, arrays, functions, methods, object oriented programming, libraries, etc. At least study those topics (especially OOP and write a small project with them) before messing with frameworks. Many use OOP and you will struggle if you don't even know how to program in the language, although if you knew how to program it would be less of a struggle than if you didn't know either OOP/Programming in general.
It's not a skill you develop over night, write code, read code, debug code, and repeat until you're familiar with the general concepts.

How to use PHP for large projects? [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 3 years ago.
Improve this question
The question has been asked: No PHP for large projects? Why not? It's a recurring theme and PHP developers--with some cause--are forced to defend PHP.
All of these questions are valid and there have been some responses but this got me thinking. Based on the principle that you can write good code in any language and bad code in any language, I thought it worth asking a positive rather than negative question. Rather than why you can't, I wanted to ask how you can use PHP for large projects.
So, how do you write a large, complex, scalable, secure and robust PHP application?
EDIT: While I appreciate that the organizational aspects are important, they apply to any large project. What I'm primarily aiming for here is technical guidance and how to deal with common issues of scalability. Using an opcode cache like APC is an obvious starter. Cluster-aware sessions would be another. That's the sort of thing I'm getting at.
For the most part, the problems with php are not so much with the language. The problems come from the coupling of a low barrier of entry and the lack of any infrastructure to avoid common programming problems or security problems. Its a language that, by itself, is pretty quick-and-dirty. Nevertheless, it still has many advantages for large-scale web apps. You'll just need to know how to add in some level of infrastructure to avoid a lot of the common web programming blunders. See - What should a developer know before building a public web site for help with this.
You need to learn about the reasons php can make your web app to be insecure or problematic and learn to mitigate those problems. You should learn about how to use php to securely access your database. You should learn about avoiding SQL injection. You should learn about evil things like register_globals and why you should never ever use them. In short, you should do your homework about your tool before just diving in for a real-world, large-scale, web app.
Once you are educated, it comes down to you'll probably want to build a framework or use a preexisting framework that will mitigate these problems. Popular frameworks include PEAR and Zend.
Also, useful questions that might help:
What should every php programmer know?
What should a developer know before building a public web site
Using PHP for large projects isn't different than with any other language. You need experience and knowledge in writing maintainable and extendable source code. You need to be aware of security pitfalls and performance concerns. You need to have researched your problem domain and be well familiar with it.
In the end, same as any other language - what you need are high-quality and well-motivated developers.
i know, this is a little out of date, but still, i'll tempt an answer ...
use Haxe/PHP ... i could delve into details ... but if you look at the language, its features, and the nice way the PHP API is encapsulated into something rather consistent, you will soon see, what PHPs problems are ... and also, you have all the benefits of Haxe in the end ...
edit: this was a serious answer ... Haxe/PHP automatically solves a lot of problems mentioned in the post flagged as answer ...
register_globals is turned off ... you get your parameters through the php.Web
using the SPOD-layer (same API for php) for the database automatically takes care of escaping (and will automatically provide your model (and templo is quite a good template engine, so that should help for your views))
having a typed language, you are more likely to write better code ... plus language features as generics and enums are very powerful ... and there is a lot of compile time magic in Haxe that is also of interest ... a more powerful language is always good to adress complex problems ...
if you want to use other PHP frameworks, you only need to write the external classes and everything will work as expected ...
i think Haxe is a very good answer to "large", "complex", "secure" and "robust" ... scalability does not come from Haxe itself of course ... but still, if you check out haxelib, then you find many things, that would help for scalability ... such as memcached (you will have to change neko.net.Socket to php.net.Socket in memcached.Connection) ...
if you really want to use the PHP language, and not just the platform, Haxe won't help you of course ...
You do as you would in any other language or any other enviornment.
There are a couple of simple steps in project development:
Organization; You need to organize everything, having documentation, uml diagrams and other pre-work done, before you start programming.
Structure; Before you start coding and also aftter starting, you need to have a focus on structure, meaning that you always need to do it correctly and not do any spagetthi solutions. Keep code simple and well commented.
These two points, are simple and apply in all development areas, despite the language. Keep it simple and well documented and you will find that developing a large scale web app in PHP is as easy as it would be in ASP.NET, Ruby or whatever.
However when we come to the development stage, you need to get a nice IDE, use a good database, use a repo., get an MVC / Template system, this runs in the "Structure"-part though.
Just as a side point, splitting the application into different layers: DLF ( Data, Logic, Front ). Use at least these three layers and you will find that the development will go easy.
Use Model-View-Controller framework. It's been said, yes. And, have at least one engineer for each part.
Model: Your DBA should write the Model code. No should else should be allowed to write SQL statements.
View: The one with the best knowledge of CSS and Javascript should do the view part. He/she should write the least PHP code, he is the one using PHP variables.
Controller: She's the real PHP coder, and also back-end server engineer, hopefully, with or without using other script languages.

Categories