How do web frameworks..work? - php

I keep seeing all these cool new frameworks for web dev, but am very confused, because 95% of the info I read is all just hype, how do they work?
Is it as simple as providing a link in your html to a server that hosts the framework? Or do you have to download the framework, and install it on your own server?
Do web frameworks work with Winhost.com (windows-based hosting with php), or the many other windows-based hosting providers? Sorry if this is a stupid question, but the pages I have visited are very confusing!

Most of the frameworks would require you to download them and re upload them to your hosting.
Since having some crazy requirements would hit the popularity of such framework, most of the populars one tends to have as less as possible requirements. I.e. you don't need to have specific PHP extensions or PHP settings, so it would be possible to use them on any hosting(PHP5 hosting, zf, symphony and other don't play well with PHP4).
In term of what a framework brings you, you can see a framework as a big code base the you can use to make your development faster. You don't have to reinvent the wheel. Plus a framework would force you to code more cleanly.

Generally speaking and in a nutshell, they allow you to generate HTML (with code) instead of providing static pages to the users. This also means you get to code less and don't repeat yourself.
PHP and Ruby on Rails are examples of web frameworks. You have to get them installed on a server.

Here's how it works.
Static HTML page is the oldest type of webpage. You write some HTML code, and when the server receive request from browser it parses the URL and determine which HTML file corresponds to the URL.
Dynamic page, is similar to static HTML page; but instead of writing HTML code, you write PHP/ASP/Python/CGI/etc code that writes HTML code.
As it happens, a lot of dynamic websites shares a large chunk of similar PHP/ASP/Python/CGI/etc code. A web framework is a set of pre-written code someone else have written; so instead of you writing the code, you offload half of the code-writing to the web framework's authors.
Different framework have different requirements. The simplest are just several simple PHP pages you can include() into your own codes (i.e. installing is a matter of copying the PHP pages into the same directory as your own code). The more complex one might reverse the role, they take control how the page is processed (i.e. installation is more involved, they might need to tweak the server's configurations).

Related

Is it really required to use express or other framework with node.js?

I am a new learner to node. I am getting some issues with node. Like if it is really required to use any framework/module like 'Express' etc with node?
Cant we just simply create a web application similar to PHP or asp etc. In PHP we can simply create files & we know where to put our files & rest of the things handled by server itself.
PHP Frameworks : CodeIgniter, CakePHP (Tell us where to put code, means MVC etc)
Node Frameworks : Express , Fab.js (Tell us without using these we cant proceed easily)
For example i want to create a simple Profile edit form for a student. In php i can simply create a form in HTML, display already filled values by user in fields & can add some validations on it. But with node,how we can do it?
Where actually should i place my server side files?
Do i really require any framework(express) to do that in node?
Can i write a mixture of html & Node.js together as we usually do in PHP using < ?php ?>
Like if it is really required to use any framework/module like 'Express' etc with node?
No. As with any framework, it just makes life easier for you by doing some common things for you.
In PHP we can simply create files & we know where to put our files & rest of the things handled by server itself.
Typical Node apps have the server built in and have to do URL routing themselves (this is what Express does).
Typical (small) PHP apps use a separate server and let it handle their routing for them.
You can do that with Node, but you need to have some way to link the server to the specific JavaScript program you want to run. You could write all your JavaScript programs to conform with the CGI specification, but CGI isn't very efficient and (my impression is that) most people choosing to use Node do so for performance reasons.
Where actually should i place my server side files?
This is up to you. There are lots of approaches you can take to organise your code.
Can i write a mixture of html & Node.js together as we usually do in PHP using < ?php ?>
PHP makes it easy to mix your business logic with your display logic. This makes it very easy to knock out trivial programs. It also makes it very easy to make non-trivial programs a maintenance nightmare.
As far as I know, Node doesn't come with a templating language but plenty are available through NPM. I'm not aware of any that let you splurge raw JavaScript into the middle of templates, but that isn't a feature I'd consider desirable.
you can put your node files anywhere, it's common to have the main entry point to your app at root level of your project. Then libraries generally are out in a subdirectory, 3rd party modules are managed through npm and install to node_modules by default. node_modules is on node path by default so they can be referenced without paths ie require('async'), assuming you have installed npm async
you don't need any framework, node provides all the tools necessary to create a server in its standard library
node has a couple of templating libraries, I'm pretty sure most of them allow you to mix html and a couple of expressions that evaluate to js, like loops and conditionals. Some might allow arbitrary js, but I don't have any experience with them

What is a good way to set up a site template with PHP on IIS6?

I am not very experienced with PHP. I have a site I'm maintaining that is on IIS6 using PHP. Right now it is using include files and querystrings to server up content.
For example:
http://mysite/index.php?maincontent=services&subcontent=service1&nav=subnav1
We want to change the site so that URLs look more like (for example):
http://mysite/commercial-services.php
But, I don't want to duplicate code and include files in the 30+ files of the web site.
Is there an easy way with php to have a template that keeps the short urls but allows you to use the same layout file for multiple pages?
I do mostly .net web sites so I guess what I'm looking for is something comparable to asp.net master pages.
I also looked at php frameworks, namely codeigniter. However, that by default leaves an index.php in the middle of the url. From what I read we would need to use some type of isapi rewrite to get rid of that. I can't do that because I don't have access to the server and they don't want to install things on the server.
Is there anything simple we can use or are we limited to using includes?
Update:
For this I ended up converting the site to .net. It was much faster and easier (for me) to do than figure out how to set up something with PHP.
I'd say look at rewrites not frameworks if all you want to do is change the urls, that way you backend php can stay the same but you still get the nice urls.
There's loads of tutorials, quick google gave me:
http://articles.sitepoint.com/article/guide-url-rewriting

Mixing Python web platforms PHP, e.g. - Mediawiki, Wordpress, etc

Is anyone developing application integrated with Mediawiki - using Django or other Python web development platforms using mod_wsgi?
Would be very interested to find out what has been done in this direction and maybe there is some code available for re-use. (I've started creating wiki extensions working with MW database in python whose output is injected via Apache's include virtual directive. it works ok, but a bit slow so far - maybe I can optimize it though)
Basically I would like to have certain parts of displayed wiki pages be prepared with python.
Has anyone reproduced common MW skins in python templates?
edit: found this nice video showing how PyCon site does just that (not with MW though) - using custom template loader
http://showmedo.com/videos/video?name=pythonNapleonePyConTech2&fromSeriesID=54
Thanks.
There are so many different ways to do this.
You can make a mediawiki skin that uses iframes and inserts things from a Python server.
You can write a python app that accesses mediawikis data somehow and outputs it.
You can put a Python server in front that extracts the content from mediawiki and put's it into a page that is otherwise generated from Python.
You can use deliverence to skin mediawiki, and use it's pyref functionality to call pythonscripts and insert that into the skin (I think, I haven't done that myself).
Which way is best for you completely depends.
Can't you use Mediawiki HTTP based API? Loose coupling is great.

How to combine requests for multiple javascript files into one http request?

This concept is a new one for me -- I first came across it at the YUI dependency configurator. Basically, instead of having multiple requests for many files, the files are chained into one http request to cut down on page load time.
Anyone know how to implement this on a LAMP stack? (I saw a similar question was asked already, but it seems to be ASP specific.
Thanks!
Update: Both answers are helpful...(my rep isn't high enough to comment yet so I'm adding some parting thoughts here). I also came across another blog post with PHP-specific examples that might be useful. David's build answer, though, is making me consider a different approach. Thanks, David!
There are various ways, the two most obvious would be:
Build a tool like YUI which builds a bespoke, unique version based on the components you ticked as required so that you can still serve the file as static. MooTools and jQuery UI all provide package-builders like this when you download their package to give you the most streamlined and effecient library possible. I'm sure a generic all purpose tool exists out there.
Create a simple Perl/PHP/Python/Ruby script that serves a bunch of JavaScript files based on the request. So "onerequest.js?load=ui&load=effects" would go to a PHP script that loads in the files and serves them with the correct content-type. There are many examples of this but personally I'm not a fan.
I prefer not to serve static files through any sort of script, but I also like to develop my code with 10 or so seperate small class files without the cost of 10 HTTP requests. So I came up with a custom build process that combines all the most common classes and functions and then minifies them into a single file like project.min.js and have a condition in all my views/templates that includes this file on production.
Edit - The "custom build process" is actually an extremely simple perl script. It reads in each of the files that I've passed as arguments and writes them to a new file, optionally passing the entire thing through JSMIN (available in all your favourite languages) automatically.
At the command like it looks like:
perl build-project-master.pl core.js class1.js etc.js /path/to/live/js/file.js
There is a good blog post on this # http://www.hunlock.com/blogs/Supercharged_Javascript.
What you want is Minify. I just wrote a walkthrough for setting it up.
Capistrano is a fairly popular Ruby-based web deployment tool. If you're considering it or already using it, there's a great gem that will figure out CSS and Javascript dependencies, merge, and minify the files.
gem install juicer
From the Juicer GitHub page, it can figure out which files depend on each other and merge them together, reducing the number of http requests per page view, thus improving performance.

One code, many websites

I need to develop a project that would allow me to instance many copies of a website, but each copy needs to be a separate website. I could upload the same code to many different accounts, but I would prefer to have only one copy of the code. Each website would be an "instance", so to speak. This way I could upload the code once and update all the websites at the same time.
For technical reasons I need to use PHP (but I'm interested in the other options too, for my own knowledge), and I thought Jelix could be a good choice of framework. Are there better options out there?
You can have all code in one directory, and then create virtual subdirectories in all your web sites, which all point to this directory. This is how Microsoft solves the problem in SharePoint.
The easiest bet is to have all the websites link to one server (perhaps distributed).
Pass the calling URL through your webserver to generate configuration information. Use those passed URLs to define the differences between each site.
Beyond that, the framework is almost immaterial to the question, so I'll leave it to someone else to answer.
Just remember, if you make 20 copies of the same code, that's 20x the time it'll take to fix bugs.
If you're using UNIX or Linux for a web server, you could create one master copy of the PHP code, and then use symbolic links to the actual files that are in separate directories with virtual websites set up in Apache. You could also put site-specific config files under those directories, but the bulk of the PHP code would be resolved as symbolic links to the "master" code.
I'm not sure what kind of websites you're talking about, but why not use an already developed application like Wordpress or any other cms? The code is identical on every website, and you can easily update it. The website-specific data is only present in the single configuration file, and the MySQL database.

Categories