Mini Course PHP , PHP
- 28/08/2008
Mini course in PHP (Part 11) - Includes
Hello all good people?
As promised, we will begin to make a simple news. With administration and everything. Below is the scope of how our system will be:
- Administration
- Login page;
- Go to Registration / Editing / removal;
- Registration of categories news / Editing / Removal;
- Register for news / Editing / Removal;
- The visual
- List of Categories on the menu;
- Listing of news (with or without a category filter);
- Form to search for news;
- Top 10 news;
- Send news by e-mail to a friend;
But remember that we still have much to learn about the PHP language. I decided to teach the rest by doing some simple systems, to make learning more dynamic and that what is learned is seen in practice.
Before we start our system, we have some very important things to learn. They are:
1. Includes;
2. MySQL basic commands;
3. Commands for working with PHP Mysql.
INCLUDE
As the name suggests, include is a command that INCLUDES the contents of another file where it is called. It's like if you copied the file and colasse code where you want to use.
See how we will use include in our system of news: it can enter into our management to be logged. However, each page needs to be done a test to see if there is someone logged in and therefore allowed to see the page. Because we have the assurance that no one without a password to access our system. So we have an IF at the beginning of each page. The IF would be something like 'If someone has logged in, then show the page. Otherwise return to the login page '. Right? IF not to copy this and paste on ALL pages, we'll create a file that contains this and we will run the IF INCLUDE calling this file on every page of the administration. It was clear this idea?
What's the point of using the INCLUDE? Well, imagine that your administration has 20 pages. And his rule to validate if there is someone logged change. Oh you'll have to change the 20 pages containing this IF. Using INCLUDE this problem ... just as all 20 pages using the IF that is written in the file that will be included.
We use an INCLUDE as follows:
Include ("path");
The file path is the folder and file name to be included, for example: "includes / validausuario.php." To include a file that is a folder below, you will use ".." out of the folder where your file is running. For example: ".. / includes / validausuario.php." And so on ... if you want to include a file that is three levels below you use ".. / .. / .. / includes / validausuario.php"
See this in practice. Consider the file a.php as follows:
- <?
- ; $ Variable = "I setada b.php file";
- ?>
And consider the file b.php as follows:
- <?
- "a.php" ) ; include ("a.php");
- ?>
Understanding: The file b.php is calling (with the include command) a.php the file. If we run the file b.php we get the following output:
I setada file a.php
But why? Because ALL of the contents of the file was included in the file a.php b.php.
It was clear?
IMPORTANT
If the include file does not find the requested file .. He WILL NOT GIVE ERROR ... the script will usually follow. So in many cases, instead of using the command include () is more advisable to use the command REQUIRE, because if the file is not found the script will not continue running. The PHP parser will give error.
To learn more about INCLUDE or REQUIRE access the documentation on php.net: http://br2.php.net/manual/pt_BR/function.include.php
This example shows that was used is available from: http://www.marcelosabadini.com.br/mini-curso/include/
Because MySQL is a very extensive, I will do a post specifically for him. I'll post over the weekend.
Meanwhile, read the php.net documentation because it is very important. Do some example ... even this can be until I spent .. And create another example for you to practice.
I hope I have been clear enough. If you have any questions or realized that I did not say something important, please comment POST.
A big hug and until the next.



7 Responses to "Mini course PHP (Part 11) - Includes"
Dude, very nice tutorial!
Once you have some time I will follow him step by step
Congratulations and thank you!
For Diego (15 comments) on 03.09.2008
First I want to congratulate you for this tutorial that not even started yet, but I know it'll be great with him.
I'll start from scratch because my notion of PHP is minimal!
When a little more familiar with the matter back to comment again and thank you once again!
See you soon!
By Ricardo Leandro (2 comments) on 06/09/2008
Marcelo speaks.
Congratulations on your initiative man, I am following your course and you're very nice.
I would like to know how to put intellisense for PHP in Dreamweaver. I was using Aptana and Zend (they have intellisense), but now with Dreamweaver must enter the entire command. You know how I fix this?
For Nosbielcs (3 comments) on 09.10.2008
Nosbielcs Hello, how are you?
First, thanks for stopping by my site and enjoy!
kra intellisense ... this would be the 'auto-complete' right? (According to wiki)
So, Dreamweaver has an intellisense / auto-complete very good for PHP (I do not know other languages), but he even tries. Do this, begin typing a command PHP, for example 'str_' and press CTRL + SPACE.
See it enables Intellisense / auto-complete. I think q q would be automatic! but that's okay ... It auto-complete only the super-global ($ _GET, $ _SERVER, $ _POST, $ _COOKIE, $ _FILES, $ _REQUEST, $ _SESSION) automatically.
For Marcelo Sabadini (112 comments) on 10.09.2008
do not forget to type the command inside a PHP tag: <? ?>!
For Marcelo Sabadini (112 comments) on 10.09.2008
So Marcellus, is not quite what I wanted. I wanted to get the Variables set understands. The CTRL + SPACE only serves to describe the end of the command. He did not arrow a variable declared in the scope of the code.
For Nosbielcs (3 comments) on 09.10.2008
Nosbielcs, eh .. I really think this case q does not scroll.
For these and other reasons, can not fail to use Zend. I'm in love with this IDE rsrsrsrsrsr
Zend Studio S2 HaHaHaHa
* I preciptei .. I saw the picture in the Wiki at a glance and I was completing functions q rsrsrsrsr
For Marcelo Sabadini (112 comments) on 10.09.2008