Professional Documents
Culture Documents
A.ei
1.
is
2.
3. Syntax
4.
(Variables)
5. s (String)
6. a (Operators)
7. n
sn
8. (Loop)
9. While
10. For
11. a (Array)
12. (Function)
13. PHP
14. $_GET
!
15. $_POST
!
B.a
n ei
1.a
n ei u |
( Advanced PHP Tut or i al i n Bangl a)
2.ei 0 1234 u ( PHP Dat e Funct i on Tut or i al i n Bangl a)
3.ei i4k9 1234 u ( PHP I ncl ude Funct i on Tut or i al i n Bangl a)
equi
4.ei
1234 ( PHP r eq
ui r e Funct i on Tut or i al i n Bangl a)
5.ei 1i 1234 u ( PHP Fi l e Funct i on Tut or i al i n Bangl a)
6.ei 1i ? u ( PHP Fi l e Upl oad Tut or i al i n Bangl a) 7.ei k
u ( PHP Cooki e Tut or i al i n Bangl a)
8.ei 034 u
u ( PHP Sessi on Tut or i al i n Bangl a)
9.ei e hK u ( PHP Er r or Handl er Tut or i al i n Bangl a)
10. ei 0i 1234 ( PHP Mai l Funct i on Tut or i al i n Bangl a)
11.
11.ei 1l u ( PHP Fi l t er Tut or i al i n Bangl a)
C.ei 0Po
R
7.0
ia4i
0
ia4i e pg ep
34 ijk ( Cr eat i ng Fi r st Appl i cat i on wi t h CodeI gni t er )
Downl oad
& I nst al l
Tut or i al
in
A.ei
1.
:
o$ %
u ei' o$
6 o$ ei'
!( 2 Process
3:
3
: :
(Picture,Content etc)
: %
3 :(math calculation,file operation etc)6 e
ei' (PHP) ?:
PHP Hypertext Preprocessor e i!,k p,HTML-embedded skp ($ei' e
2.
:
o$ %
p
Au$A
6 N2 6, e 76 % ,kin o$(6 %2i e @ is :6 ,
o$
3 apache e ai ei' % e
! o$o is :$
3:MySQL, (
6 2e o$( O o$ 3$P$ e6k (( ' :$ o$(
2e , R
:c e e e o$
3 is : ( ei is ,$ 3% %: %: is :6
,o$A
,c
XAMPP.XAMPP
e
!u!
is
http://www.apachefriends.org/download.php?xampp-win32-1.7.3.exe a o$ e 6 is
:
in
;
!s XAMPP e eA %i
:
! k o a
a 6 -
3 Ui
is :$2
(i e XAMPP Control Panel %i
:6 a
n % 3: C Ui is
:
6, C:\Program Files\xampp C:\xampp ei
e @ start click (Apache
e MySql)
Apache o MySql ' bu eU http://localhost ' 6 e
%
English k
ei
A % 7 % 6 is mn ,$2 a
n % muA e ,
2(
)
3.
:
o %
4.
:
o$ %
ei'
!
6 ai i extension .php
6 ,3: .html
6, ei'
! execute
,
* ei'
! e p6A a <?php 'h :$ e ?> 'h :$
; ,
* e ei' Scripting Block(<?php e ?> e 6 3
,$
$ e b ) !kn 6
6
*p6A %: instruction(code line)
k d
; ,
o e %
! e! (
!/U$ % 3 , ) e ' 6
<?php
echo"This is my first php page";
?>
e
A mypage.php
,
$ htdocs browse
:$ : save in e $($e
bu eU http://localhost/mypage.php e en : ' 6 %u
:6
";
";
";
";
";
e 6
k
<?php
echo "Hello World!";
echo "Hello World!";
?>
%
: ei'
! 6
s ,e pA 6 6
:6
5.
:
o$ %
6ei'
6
$ ei 'hA :$ ai 6 , ,
*
case sensitive.
3 $a_number and $A_number :A %:
, ei' e :bc6
*mk ei'
6
,$
$variable_name = Value;
u %'6
(6 3:
6
6 'i 6,1.<?php
2.$hello = "Hello World!";
3.$a_number = 4;
4.$anotherNumber = 8;
5.?>
d6:
1.ai
letter or _(under score) :$ 6 ,
2. @ alpha-numeric characters o underscores. a-z, A-Z, 0-9, or _ .
6
3.
s
33: e a@ ,$ 6, ___underscore ($my_string) a
N ,6
ak($myString)6 ,
6.
:
o$ %
ei' s e6k , o (E %' ,$ei' Career e ei s e (tg g 6i e h @
%
s , %( e D6E 6 ,e s e , ,6 a
e $ store
6 '
: ei s : D6E 2,e $ store ,$2 % echo ,$2
1.<?php
2.$my_string = "o merciful make me bold and brave!";
3.echo " o merciful make me bold and brave!";
4.echo $my_string;
5.?>
e6k6 Double quotes d s D6E ,$2 e Single quotes d s D6E 6 ei R,6
, %6 o apostrophes '6
1.<?php
2.$my_string = o merciful make me bold and brave!;
3.echo o merciful make me bold and brave!;
4.echo $my_string;
5.?>
3: s e 6 single quotes , : ,$ 6, e echo PHP it\s neat
% e %66 double quotes , e6 2 @ %2
3 single quotes e i
ei'
3 d6:A %' , e :A @6
pg ($ e
kt ^6 ,$,n ei'
6 e
o$ %2
3 :$ , i s
3$
quotation , 2Ni , heredoc,e 66
s
! 6 , , 7 ,'
: e 6 ,$1.<?php
2.$my_string = <<<TEST
3.He will be succeeded here
4.and here after!
5.TEST;
6.echo $my_string;
7.?>
e 3: s
6, $A ai
$ 6 ,*<<< 2 identifier %2 3 % , 6 , heredoc %(
3 % TEST, 2
*
;o eA , 2 e
k :$
; ,
*e i e i ,,(indent)
iA 3
%u ' 6 %
3,6 % <br>(i
b
:$ ^6 ,$)( s e 6 ,
7.
:
o$ %
English
Example
Addition
2+4
Subtraction
6-2
Multiplication
5*3
Division
15/3
Modulus
43%10
01.<?php
02.$addition = 2 + 4;
03.$subtraction = 6 - 2;
04.$multiplication = 5 * 3;
05.$division = 15 / 3;
06.$modulus = 5 % 2;
07.echo "Perform addition: 2 + 4 = ".$addition."<br />";
08.echo "Perform subtraction: 6 - 2 = ".$subtraction."<br />";
09.echo "Perform multiplication: 5 * 3 = ".$multiplication."<br />";
10.echo "Perform division: 15 / 3 = ".$division."<br />";
11.echo "Perform modulus: 5 % 2 = " . $modulus ?>
e
:-
English
Example
Result
==
Equal to
$x=$y
False
!=
Not equal to
$x!=$y
True
<
Less than
$x<$y
True
>
Greater than
$x>$y
False
<=
$x<=$y
True
>=
$x>=$y
False
8.
:
o$ %
6 u
action
$ n
sn ^6 ,$@ % % o$i e e feature
3(
6 'i 36 3:
u % i : 12 %( i 6,
: Good Morning % 3:
u 5
i 6,
: Good evening ei @ e
'$o : o a!n! ( 6 Conditional
statement e :,condition e u t ei' s$k$ ( 6i
ei'
6 $ @ Conditional statement %2*if statement
*ifelse statement
*ifelseifelse statement
*Switch statement
* I F STATEMENT
if statement A :$ 2
! execute ,$ 3 %:
:$ condition A true ,$' u:, %u ,
Have a nice day 3: p : Saturday ,$
3:
!
1.<?php
2.$d=date("D");
3.if ($d=="Sat")
4.echo "Have a nice Day";
5.?>
* I FELSE
F ELSE STATEMENT
%c o
6 e
2 3: k 6, , , 3: k ,
iei ifelse statement
e u:,e(6 a $ % si ,
e @ e ei'
! :$
1.<?php
2.$d=date("D");
3.if ($d=="Sat") echo "Have a nice Day";
4.else
5.echo Today is not saturday;
6.?>
: condition
3 :$2 3:
true ,$ a
n
!
3:
: 3: Saturday ,$ 6, %u ,
Have a nice day % 6 , Today is not Saturday.
* I FELSEI
F ELSEI FELSE
F ELSE STATEMENT
ei statement d e e@
! b execute 3$
view source
print?
01.<html>
02.<body>
03.<?php
04.if ($number>=60)
05.echo "First Division";
06.elseif ($number>=45 and $number<60)
07.echo Second Division;
08.elseif($number>=33 and $number<45)
09.echo "Third Division";
10.else
11.echo Failed;
12.?>
13.</body>
14.</html>
9.
:
o$ %
@
i6:pg e ,c e 'n i ei gbt $ i i 3$ :$
e( 3$
,c e e statement
3 :$ e
! b
:c $ execute 3$ 36k %:
;
,$
4 @ %2While Loop
Dowhile Loop
For Loop
Foreach Loop
10.
:
o$ %
n e 3: i=6
:i 6, ,?' 6
This is line 6
This line is outside while loop.so it will not repeat.
: A p
' 2Ni e
! execute ,$2p
execution e
' 2
3 A repeat ,
?n while loop e p
i ei
' ,$
11.
:
o$ %
Output
The
number
is
1
The
number
is
2
The
number
is
3
The
number
is
4
The number is 5
12.
ei a
u ( PHP Ar r ay Tut or i al i n Bangl a)
:
o %
e
e single value e t(container).n a e@ value container te a ,
2 u: (R6
3 p6A u: :c value %2-key index
3 : u:A
,
@ % 2 2 , s %2 e 3: e(
single variable e store 6 ' 6, e
,$city1= Dhaka
$city2= Chittagong
$city3= Rajshahi
$city4= Sylet
$city5= Khulna
$city6= Barishal
n e a e( e e @ 6 a @ (> d6 ,c 2 u: k(series of
element) 3 u:( index 0
, k u6
a
3 ' ,A ,c1.<?php
2.$city=array(Dhaka, Chittagong, Rajshahi, Sylet, Khulna,
Barishal, Barishal);
3.?>
6 3: % 'i 6, a ei !l 6 :6 ,=> ei aA :@ % 'c ei u
aA starting index 2 :
, 6, e 6 ,
1.<?php
2.$city=array(2=>Dhaka, Chittagong, Rajshahi, Sylet, Khulna,
Barishal, Barishal);
3.?>
ei a
3 u: g ^6 ,6 6 index :c
a
a
( ASSOCI ATI VE ARRAY)
e6k6 g index/key
: % 'i string o , 6 ei associative array 3:
1.<?php
2.$ages = array("adnan"=>32, "rezwan"=>30,"refat"=>34);
3.?>
li434 a
( MULTI DI MENSI ONAL ARRAY)
ARRAY)
e e a 6 p6A u: eA a ,6 % ei a p6A u:o eA a ,6 e
e %o
1.<?php
2.
3.$continents=array("Asia"=>array("Bangladesh","India","Pakistan"),
4."Europe"=>array("England","France")"Africa"=>array("Kenya",
5."Libya","Somalia"));
6.
7.?>
a
r 92
FOREACH LOOP
@ eA associative array %2 e % gbt 6 ' foreach statement : e 6 3:
1.<?php
2.$city=array(Dhaka, Chittagong, Rajshahi, Sylet, Khulna,
Barishal, Barishal);
3.foreach ($city as $value)
4.{
5.echo $value.<br>;
6.}
7.?>
Output
Dhaka
Chittagong
Rajshahi
Sylet
Khulna
Barishal
Barishal
13.
:
o %
e ,c e
3 %
!b :6 e
i @
! p
!b ic6 execution 6
e ei' e g k 6 p 700 eo
l i %2 ei'
6
e 3 , 6i e execute , %
3 (
e 3
2
j
1.function functionName()
2.{
3.code to be executed;
4.}
A:
: e :
3
:i
3
7 3 A
ak _ : ,6 ,m : ,
e simple
3 : %
01.<?php
02.function writeName()
03.{
04.echo "Md.Rejoanul Alam";
05.}
06.
07.echo "My name is ";
08.writeName();
09.?>
Output
My name is Md.Rejoanul Alam
1234
0qa
0qa
3( %o A u 3,e e: PHP variable e 6i
e
b 6
,3
01.<?php
02.function writeName($fname)
03.{
04.echo $fname . " Alam.<br />";
05.}
06.
07.echo "My name is ";
08.writeName("Rejoanul ");
09.echo "My Father's name is ";
10.writeName("Samad");
11.echo "My brother's name is ";
12.writeName("Anjirul");
13.?>
Output
My
name
is
My
Father's
name
My brother's name is Anjirul Alam.
% u:,
is
Rejoanul
Samad
Alam.
Alam.
01.<?php
02.function myGreeting($firstName, $lastName){
03.echo "Hello there ". $firstName ." ". $lastName."!<br />";
04.}
05.myGreeting("Jack", "Black");
06.myGreeting("Ahmed", "Zewail");
07.myGreeting("Julie", "Roberts");
08.myGreeting("Charles", "Schwab");
09.?>
output
Hello
there
Hello
there
Hello
there
Hello there Charles Schwab!
Jack
Ahmed
Julie
Black!
Zewail!
Roberts!
14.
:
o$ %
e6k ei' 36 2
, e 6 p$( $ e2 iu
6
6 ^6 ,$ei 6
ei'
:$
3$ e ei' :$i e ,$ei'
6 :A
$ %2 3 ,6
!(iu i) 6 %6 ^6 ,$$_GET e $_POST.e ei'Aee
: , 3 :A i l % eA %2
1.<form action="welcome.php" method="post">
2.Name: <input name="fname" />
3.Age: <input name="age" />
4.<input type="submit" />
5.</form>
e @ % A6 $($ : rezwan e age : 24,e k %u e
Welcome
rezwan!
You are 24 years old.
15.
ei $_GET
$_GET 0g ( PHP $_GET Met hod)
:
o$ %
6
GET
! e > 6
bu eU p:6 ,$ e i
:6 $62N 6 k 6
> 3
6 eA E %2 @6 c 250 A character (e % e bu u
3 6: URL e
D:a 6: ,)
3
1.<form action="welcome.php"method="get">
2.Name: <input name="fname" />
3.Age: <input name="age" />
4.<input />
5.</form>
16.
:
o$ %
ei d66
3 6
i >
, 6
u
:6 bu eUo p:6 ,$
e @ , 36 ic 6
>6 (% c 8Mb 3n > 3$)
<form action="welcome.php" method="post">
Name: <input name="fname" />
Age: <input name="age" />
<input />
</form>
o4 0
4
t
4
al 6
, GET Method %
6
e iu
password i6:
kt POST Method ,
B.a
n ei
1.
a
n ei u |
( Advanced PHP Tut or i al i n Bangl a)
:
o %
webcoachbd.com e ei
ei' a!n! Au
3-ei'
,k,i,
!,e
,n i6:
2.
ei 0 1234 u ( PHP Dat e Funct i on Tut or i al i n Bangl a)
:
o %
Output
2009/05/11
2009.05.11
2009-05-11
e %
3 A 2n
A : :
3.
ei i4k9 1234 u ( PHP I ncl ude Funct i on Tut or i al i n
Bangl a)
:
o$ %
% ic i eku %(i ei' e e i a a % ei' i i $ :6
include() :$
Require()- , fatal error((6 )
: e skpA eku n :
Include()- , 6 : e skpA eku
e :A :$ a
' 3$
3 % 3: e
,
,!,
3 a
3 % '
3 % o$ i
i e
: 6, e ei' i
(
,
,!, i6:) D6E a
e :A :$
3(
:6 %: %: p6A
% e(
3( 6 ,% 3: ei include i
2 %!
e
6
3( 6,
($i 3k ,b
($ %
3( 6
,u:,,@ menu.php e i aa2 ' 6
1.<a
2.<a
3.<a
4.<a
5.<a
6.<a
href="/default.php">Home</a>
href="/tutorials.php">Tutorials</a>
href="/references.php">References</a>
href="/examples.php">Examples</a>
href="/about.php">About Us</a>
href="/contact.php">Contact Us</a>
e
3( 6 , e
view source
print?
01.<html>
02.<body>
03.<div>
04.<?php include("menu.php"); ?>
05.</div>
06.<h1>Welcome to my home page.</h1>
07.<p>Some text.</p>
08.</body>
09.</html>
4.
:
o$ %
require() include() e 6i @ t , %' e u t e n6 %2
Include() e e
:
01.<html>
02.<body>
03.
04.<?php
05.include("wrongFile.php");
06.echo "Hello World!";
07.?>
08.</body>
09.</html>
Error message:
Warning: include(wrongFile.php)
failed
to
No
such
file
or
directory
Warning: include()
Failed
opening
(include_path='.;C:\php5\pear')
in
C:\home\website\test.php
in
[function.include
stream
on
line
open
C:\home\website\test.php
'wrongFile.php'
[function.include
inclusio
for
on
line
Hello World!
Notice that the echo statement is executed! This is because a Warning does not stop the script
execution.
require() Function e e
:
Now, let's run the same example with the require() function.
1.<html>
2.<body>
3.<?php
4.require("wrongFile.php");
5.echo "Hello World!";
6.?>
7.</body>
8.</html>
Error message:
Warning: require(wrongFile.php)
failed
to
No
such
file
or
directory
Fatal
Failed
opening
(include_path='.;C:\php5\pear')
in C:\home\website\test.php on line 5
echo statement e eku ,$i
in
open
C:\home\website\test.php
error: require()
required
[function.require
stream
on
line
[function.require
'wrongFile.php
5.
:
o %
fopen e b :A %2 eA welcome.txta
n ei iA e d6EA r e e
3 : R
: 3 iA
as(
!)ge r
: %2 6i eA read only
!
e % 2
Modes
Description
r+
Write only. Opens and clears the contents of file; or creates a new file if it doesn
exist
w+
Read/Write. Opens and clears the contents of file; or creates a new file if
exist
Append. Opens and writes to the end of the file or creates a new file if it doesn't exis
a+
Write only. Creates a new file. Returns FALSE and an error if file already exists
x+
Read/Write. Creates a new file. Returns FALSE and an error if file already exists
e 1i 0k
CHARACTER BY CHARACTER
CHARACTER e
1i
fgetc() function A e i
e e ak u
' u:,A i
eA eA ak u
view source
print?
1.<?php
2.$file=fopen("welcome.txt","r") or exit("Unable to open file!");
3.while (!feof($file))
4.{
5.echo fgetc($file);
6.}
7.fclose($file);
8.?>
6.
:
o %
s
! e @ upload_file.php i 3e
: upload_file.php
6
! ( e
Upload_file.php skpA , e
01.<?php
02.if ($_FILES["file"]["error"] > 0)
03.{
04.echo "Error: " . $_FILES["file"]["error"] . "<br />";
05.}
06.else
07.{
08.echo "Upload: " . $_FILES["file"]["name"] . "<br />";
09.echo "Type: " . $_FILES["file"]["type"] . "<br />";
10.echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
11.echo "Stored in: " . $_FILES["file"]["tmp_name"];
12.}
13.?>
01.<?php
02.if ((($_FILES["file"]["type"] == "image/gif")
03.|| ($_FILES["file"]["type"] == "image/jpeg")
04.|| ($_FILES["file"]["type"] == "image/pjpeg"))
05.&& ($_FILES["file"]["size"] < 20000))
06.{
07.if ($_FILES["file"]["error"] > 0)
08.{
09.echo "Error: " . $_FILES["file"]["error"] . "<br />";
10.}
11.else
12.{
13.echo "Upload: " . $_FILES["file"]["name"] . "<br />";
14.echo "Type: " . $_FILES["file"]["type"] . "<br />";
15.echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
16.echo "Stored in: " . $_FILES["file"]["tmp_name"];
17.}
18.}
19.else
20.{
21.echo "Invalid file";
22.}
23.?>
?
j 1i 0
o
%(i 2 u
!( : i asE(temporary copy)
,,sE e
!A
01.<?php
02.if ((($_FILES["file"]["type"] == "image/gif")
03.|| ($_FILES["file"]["type"] == "image/jpeg")
04.|| ($_FILES["file"]["type"] == "image/pjpeg"))
05.&& ($_FILES["file"]["size"] < 20000))
06.{
07.if ($_FILES["file"]["error"] > 0)
08.{
09.echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
10.}
11.else
12.{
13.echo "Upload: " . $_FILES["file"]["name"] . "<br />";
14.echo "Type: " . $_FILES["file"]["type"] . "<br />";
15.echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
16.echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
17.
18.if (file_exists("upload/" . $_FILES["file"]["name"]))
19.{
20.echo $_FILES["file"]["name"] . " already exists. ";
21.}
22.else
23.{
24.move_uploaded_file($_FILES["file"]["tmp_name"],
25."upload/" . $_FILES["file"]["name"]);
26.echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
27.}
28.}
29.}
30.else
31.{
32.echo "Invalid file";
33.}
34.?>
skpA
: %(
i ei
i %2 ,
move_uploaded_file A ,3 :cb 6
l ( iA
,
u u:, upload e
l ( iA
,
7.
:
o %
e iu
k 6 e ^6 ,e ,c e
2 i
3 iu 6 (
:(e
:/
) % % i,
i
' 2 e ak %
i
' i i 6 'i 6
:
3 % % iu
i 6 ,c,i,
i % iu
e (
:c,ei
i k
i
3 % ei 6
(iu
o! i6:)k6 2
k
ijk
j t
setcookie() function e ^6 , k D6E 6
setcookie() function A ai <html> ( e %(
6 ,
setcookie(name, value, expiration);
namename:e k , ei A , 6 , kA
n
6
value:e k6 k ,, ^6 k ,c username(string)e last visit(date)
expiration:e oi 3 kA
:
; ,3: % ei
: 6A(kA 6k
)R
:
6, bu s
i kA 2 3
' u:, % eA k D6E
3 iu ; oiA visit 2
i 6
k 36
e :
6 e iu 6 aa % i %% 'i k
: R :6
3 % e
: 30 : :2a
n e oi s iu ignore ,2 3 30 : 6 e
i
i
1.<?php
2.$expire=time()+60*60*24*30;
3.setcookie("user", "rezwan",$expire);
4.?>
5.<html>
6......
k
ud (RETRIEVE)
RETRIEVE)
3: k
:
; ,
6, ei' $_COOKIE variable : k retrieve 3
1.<?php
2.if(isset($_COOKIE['lastVisit']))
3.$visit = $_COOKIE['lastVisit'];
4.else
5.echo "You've got some stale cookies!";
6.
7.echo "Your last visit was - ". $visit;
8.?>
ei
! isset , ,2 e P6 6
3 "lastVisit" k eo iu 6 %2 ,3:
6, iu ; visit 2 6
: 3
k
9v 01
k
2 %( e P6 ,
3 k
:
; ,2
view source
print?
1.<?php
2.// set the expiration date to one hour ago
3.setcookie("user", "", time()-3600);
4.?>
8.
:
o %
3
ep ,
,n
6 n e e
6mu
7
%
% 2,
; 2 e 6
6 2
n in e ,-o
76 %
% e6k ei'
ei @ :2ei'
iu 6
k , ei
6
asE e iu i 6(
6 2 33: sE 6
' 6,
!
6 ei'
p6A iu a ' unique id (UID) D6E
ei'
iu 6
k %(
6 ,ei'
session_start() : 6 ,
e <html> tag e %( 6 ,
1.<?php session_start(); ?>
2.
3.<html>
4.<body>
5.
6.</body>
7.</html>
%u
Pageviews=1
' u:,A page view counter(page 6
: ,2 6
: ) D6E eA isset() A
, ,ei A
'
: views %(
i
%2 3: views variable
6, % a: counter u6 % 3:
6, viewsvariable D6E e e 1
:
01.<?php
02.session_start();
03.
04.if(isset($_SESSION['views']))
05.$_SESSION['views']=$_SESSION['views']+1;
06.else
07.$_SESSION['views']=1;
08.echo "Views=". $_SESSION['views'];
09.?>
! 2
6 unset() or the session_destroy() function , ,]
unset() function :c e
2
6 ^6 ,
1.<?php
2.unset($_SESSION['views']);
3.?>
e
mg 6 session_destroy() function ^6 ,
1.<?php
2.session_destroy();
3.?>
session_destroy()
reset e e6
6
,
9.
:
o %
3: iA
as6i
6, bu ' 6 p:
Warning:
fopen(welcome.txt)
[function.fopen]:
failed
No such file or directory in C:\webfolder\test.php on line 2
iu u 6
k : 6
@(
:6 3
01.<?php
02.if(!file_exists("welcome.txt"))
03.{
04.die("File not found");
05.}
06.else
07.{
08.$file=fopen("welcome.txt","r");
09.}
10.?>
to
open
stream:
ei
!A u
!
' e ne e @ d6 e6 error , skp n , 36 e d6 ,
a R
s e hK
hK ijk
e % @ e ei' D6E
3 e ,
3 call 3ei k :A(error level and
error message) e c 'A (optionally: file, line-number, and the error context)
error_function(error_level,error_message,error_file,error_line,error_context)
Parameter
error_level
Description
%iu b 6 error report level :c ai e
error_file
error_line
error_context
E_NOTICE
E_USER_ERROR
Description
run-time errors. skp Execution n ,
Run-time notices.
iub 6 t e E_ERROR e 6
3
pg
: PHP
function trigger_error() ,
512 E_USER_WARNING
Runtime warnings generated by a call totrigger_error( )
1024 E_USER_NOTICE
Runtime warnings generated by a call totrigger_error( )
4096 E_RECOVERABLE_ERROR
Catchable fatal error.
8191 E_ALL
errors e warnings, @ level E_STRICT 2u(E_STRICT
PHP 6.0
e E_ALL e a ,)
e e
1234 ijk
e hK e n
1.function customError($errno, $errstr)
2.{
3.echo "<b>Error:</b> [$errno] $errstr<br />";
3,6 error handle % D6E , 6 'i,6i set_error_handler() e e
:,2 %
3(
36 error level e
e e u:,
01.<?php
02.//error handler function
03.function customError($errno, $errstr)
04.{
05.echo "<b>Error:</b> [$errno] $errstr";
06.}
07.
08.//set error handler
09.set_error_handler("customError");
10.
11.//trigger error
12.echo($test);
13.?>
u
! %u , e
Error: [8] Undefined variable: test
0
4 9
TRIGGER
skp
3 iu
! i 6
trigger uE 3 iu /a@ i
trigger_error() function : e ,ei u:, test 3: 1 e
' u , 6 error ,
1.<?php
2.$test=2;
3.if ($test>1)
4.{
5.trigger_error("Value must be 1 or below");
6.}
7.?>
%u
Notice:
Value
must
be
1
or
below
in C:\webfolder\test.php on line 6
e error
skp
3 ( trigger 3 e %
3( :c :6
3
error
E_USER_ERROR
E_USER_WARNING
E_USER_NOTICE
u:,
3: test e 1 e
'
, 6, e E_USER_WARNING error A , e e %
D6E error handler A ,
01.<?php
02.//error handler function
03.function customError($errno, $errstr)
04.{
05.echo "<b>Error:</b> [$errno] $errstr<br />";
06.echo "Ending Script";
07.die();
08.}
09.
10.//set error handler
11.set_error_handler("customError",E_USER_WARNING);
12.
13.//trigger error
14.$test=2;
15.if ($test>1)
16.{
17.trigger_error("Value must be 1 or below",E_USER_WARNING);
18.}
19.?>
%u
Error: [512]
Ending Script
Value
must
be
or
below
e a2
PHP
6 error_log() e li %2 e :
3 ic error log(
3 A , 6 6
)A >6
e
i R6o
ii tq
e 0 4
<?php
//error
function
{
echo
echo
handler
customError($errno,
"<b>Error:</b>
"Webmaster
[$errno]
has
function
$errstr)
$errstr<br
been
/>";
notified";
error_log("Error:
[$errno]
" someone@example.com","From: webmaster@example.com");
}
$errstr",1,
//set
error
set_error_handler("customError",E_USER_WARNING);
//trigger
$test=2;
if
{
trigger_error("Value
must
}
?>
%u
Error: [512]
Value
Webmaster has been notified
ei
! e e
i
handler
error
($test>1)
be
must
or
be
below",E_USER_WARNING);
or
below
10.
:
o %
3
! a: un
3 iu i
% ei' l 6: g,3((validate/acceptable) e
26(filter) ^6 , o ep e i (tg( o ep i i u
% 3
o ep D6E 6 i
3
i
! %
filter
i
d , e t6 ;! n un
%6
3
e ib 6
!
k
o
!
!
1234 e 2 1l
01.<?php
02.$int = 123;
03.
04.if(!filter_var($int, FILTER_VALIDATE_INT))
05.{
06.echo("Integer is not valid");
07.}
08.else
09.{
10.echo("Integer is valid");
11.}
12.?>
ei
!A "FILTER_VALIDATE_INT" d$int l ,e %u "Integer is valid"
123 e integer.
VALIDATING e 2 SANI TI ZI NG
l 2 @
VALI DATI NG FI LTERS:
: , (
3 URL E-Mail validating)
SANI TI ZI NG FI LTERS:
e s e :c
ak a:
, ,
OPTIONS e 2 FLAGS
Option e Flag
:c l a6k filtering option
3( 6 ^6 ,n l n option e
flag %2' u:, eA g validate 6 filter_var() l e "min_range" o "max_range"
option , ,2
01.<?php
02.$var=300;
03.
04.$int_options = array(
05."options"=>array
06.(
07."min_range"=>0,
08."max_range"=>256
09.)
10.);
11.
12.if(!filter_var($var, FILTER_VALIDATE_INT,$int_options))
13.{
14.echo("Integer is not valid");
15.}
16.else
17.{
18.echo("Integer is valid");
19.}
20.?>
u
! 6 options ai associative array
6 6 , e options 6 ,3: flag ,
, 6, e a ,o e
3,6 300 g n :c E @ 6i e %u ,
"Integer is not valid".
VALI DATE I NPUT
p
P6 ,6 ,
3 ib 6
!
3 % 2 6 ast %2 6 filter_input() function d
ib 6
! l 6 ,u:,
01.<?php
02.if(!filter_has_var(INPUT_GET, "email"))
03.{
04.echo("Input type does not exist");
05.}
06.else
07.{
08.if (!filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL))
09.{
10.echo "E-Mail is not valid";
11.}
12.else
13.{
14.echo "E-Mail is valid";
15.}
16.}
17.?>
03.{
04.echo("Input type does not exist");
05.}
06.else
07.{
08.$url = filter_input(INPUT_POST,
09."url", FILTER_SANITIZE_URL);
10.}
11.?>
25.}
26.elseif(!$result["email"])
27.{
28.echo("E-Mail is not valid.<br />");
29.}
30.else
31.{
32.echo("User input is valid");
33.}
34.?>
11.
:
o %
to
e
3 ii R
i R
i 3
subject
message
e
3 > ,
i( (\n) 'h d b
, e
i 70 ak
headers
parameters
:
i 3 % s ii is
6 , e php.ini iA
i a3E (
6 ,>>76 ,c?b6 ,o :
i-% 2 i 6 , %
3
,s
pi!
2 %: i(
,s i 6: e i
e
k % @ ' k u
@ % e Au i %2 e p6A Au n s %2 % % 'c
3 n(
%
i R ' % 36 76 % Au A 6 2
(2a
n !
e ei'
i ' u:, eA
k
> ,2 p
i 3 2
(a
n someone@example.com ei
i)
PHP MAI L FORM
<html>
<body>
<?php
if
(isset($_REQUEST['email']))
//if
"email"
is
filled
out,
send
email
{
//send
email
$email
=
$_REQUEST['email']
;
$subject
=
$_REQUEST['subject']
;
$message
=
$_REQUEST['message']
;
mail(
" someone@example.com",
"Subject:
$subject",
$message,
"From:
$email"
);
echo
"Thank
you
for
using
our
mail
form";
}
else
//if
"email"
is
not
filled
out,
display
the
form
{
echo
"<form
method='post'
action='mailform.php'>
Email:
<input
name='email'
type='text'
/><br
/>
Subject:
<input
name='subject'
type='text'
/><br
/>
Message:<br
/>
<textarea
name='message'
rows='15'
cols='40'>
</textarea><br
/>
<input
type='submit'
/>
</form>";
}
?>
</body>
</html>
o
:
o
:
p
:
3 ii e aA 2
3: 6, HTML Ai
:o
3: 6,
!
i R :o
ei 3A logic e ^6 ,2
e 3 k 6
A reload , e 3
: ii e aA 2 6
i
R
:
:
:e 4r dj 4 ej
ei 1R
t
a \ iu 0i
rj
e
ii i4
34ii i4
34 0g
u t form validation.
validation.q PHP
1l (Filter)
Filter) a23 u 4R4
v
C.ei
ei 0Po
R
1.
:
o$ %
ei'
Oo$ (PHP Framework) ,c e basic Platform/structure((>)
3 o$ ap
D6E6 ^6 ,$
( d6,
like k
: ei
s A 6 2n (like) 2,p6
6
!
, j e 6 i6: e( e eA ep e u:,
e2N
!
3( e Ao ,
6,e( 2No %o a @ %2 , i 76
,
$ ei'
Oo$ (PHP Framework) e eA o$
3 is : % ,i e o$ i
D6E 6 e %(
i a
! D6E
ei'
Oo$ (PHP Framework)
%(
3 ;$( 6 ,
1.PHP(; PHP Function, Variable etc)
2.Object Oriented Programming
3.MVC(Model View Controller)Structure
a ei'
Oo %2
3
n
Oo,
,,,
!i(i i6:n e
!i(i '
p 6
n e
R-
n : enpi ei' e 36i p
io
Oo :
u'n
3
!i(i,
, i6:e %
!i(i (CodeIgniter PHP
Framework) e u 2
~ @
:$
'c
2.
:
o
o %
Objects
Class
Encapsulation
Inheritence
Polymorphism
Message passing
a k ( OBJECTS)
ak D6E , 2
! e
! ,ei
!
! ( ' ) ak ,c e
(2 6
(a bundle) 3
! e n D6Ee k
,
2 u ke ak e k 6,k
3 2
6 ako
,
!
k ak ,c 2 ei'
!
uak
:6
a 6(
! @) e a o
'
ak an! ei'
6 %
3! (
: % e( 2 ak e
(2/
/
6u (bunch).e g
@ ei ak( et e u:, ,6 e
s n (ei' skpA),
3 %2 e(c
e
(bunch) 'E (ak(),6
s n e
,
3 p6 'E (ak)
m: s6nt
k ei'( d6-Procrdure Oriented way) e
3: 6 6,
:
ak
D6E
%(
%
ei
ak
e
e
/e
l
3.
(2OOPHP
! D6E %( % ei' ,
,n
sn, i6: @
6 ,
AuA , e D@3 @ 6
23 A
2
2 a(@) ( ,2
\\- ^:
pg ei 0 ijk
r4
index.php
class_lib.php
%: ak an!
! e i
i iA % ei' includes , ei'
e
i
:ei Au %: ak an!
! class_lib.php i
OOP
% k D6E A
u6k ,c
mp/k ak e 3 p ak m @
:
\\- :
e
ei k ijk
ei' skp ,
!,
i6: 2u 2A 6 3 % ak an! d66
! 6
p
i e k D6E 6 ,k D6E p
i class bA :6 , e e k ic6 :6
1.<?php
2.class people{
3.
4.}
5.?>
\\- [:
k 0 0qa
k ,c ak bpn/3 k 6 % e
D6E 6 ei
,
property
1.<?php
2.class people{
3.var name;
4.}
5.?>
:
\\- :
k 1234/
1234/0g 0qa
e k 6 e
3
, 3 properties
6 e k 6 e
6 , 3 methods ( 6 k 6 6 e: ei ! , )e
k
!/methods
i k
!/properties
6 ^6 ,
<?php
class people{
var $name;
function set_name($new_name){
$this->name=$new_name;
}
function
get_name(){
return $this->name;
}
}
?>
k 6
properties e 6 ,
\\- `:
getter e 2 setter 1234
% :A /
! D6E 2 get_name() e set_name() ei ( eA E6
' 6,
e k getter e setter ai property
<?php
class people{
var $name;
function set_name($new_name){
$this->name=$new_name;
}
function get_name(){
return $this->name;
}
}
?>
$this e li
( aki e l i)
3 6 ak : a
e e selfreferencing
e , properties e e
3 e e
! 6 k
3
function get_name() {
return $this->name;
}
\\- :
9 ei 0 ei k 9
4
ei'
ei k 6, ak an!
pg e udi
,' , k
%: e ei'
D6E ei'
e include require :
3(
:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//BN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UFT-8" />
<title>OOPHP in Webcoachbd</title>
<?php include("class_lib.php"); ?>
</head>
<body>
</body>
</html>
$rejoan
6 D6E people ak e
n% $rejoan , ei people
ak nt e ,
\\- :
new
oR
e k 6 ak D6E 6 % ei new o!A p ,
% ic e k a ak D6E 6 ei' i 2 p6A ak %: %: (s6nt
st)
<?php include("class_lib.php"); ?>
</head>
<body>
$rejoan = new people();
$riad = new people;
</body>
</html>
ak D6E k @ quote : 6, ,a
n ' e
$rejoan= new 'people';
\\- ^:
a k properties
(set)
set)
% :A ak D6E 2 people ,e % 6: properties R (set) :6 p
\\- ^^:
a k 0j e
04
e % getter
!A , ak
!6 e 6e ,
i
! 3 % setter
! :
ak i 2
3 % k
! e properties e e
i 6 a(->)'hA ,
<?php include("class_lib.php"); ?>
</head>
<body>
<?php
$rejoan = new people();
$riad = new people;
$rejoan->set_name("Rejoanul Alam");
$riad->set_name("Anjirul Alam");
echo "Rejoan's full name: " . $rejoan->get_name();
echo "Riad's full name: " . $riad->get_name();
?>
</body>
</html>
ak
! 6 %
@-12:
a k properties e e
04?
04? e
44
ak properties e e
6 %
! , 6 ,,% a (->) a
, e 6 u:,s:
$rejoan->name.
\\- ^[:
4sTk
ak e li
! %2 6, ske % ak properties e
:
:__construct()
A D6E ei' aA __construct /
! 3 %
e k 6 e ak D6E
construct
! :A %ns (__): ,sk
! k e 6 2 3k 6
(e 6) : @6 ei
! bd ,
<?php
class people {
var $name;
function __construct($people_name) {
$this->name = $people_name;
}
function set_name($new_name) {
$this->name = $new_name;
}
function get_name() {
return $this->name;
}
}
?>
@-14:
construct r e
a k 0jk
% e sk
! D6E 2,e % people ak D6E $name property :
:6 u:,:
$rejoan = new people("Rejoanul Alam");
e %: set_name()
!
'
:e6
! skp 3
<?php include("class_lib.php"); ?>
</head>
<body>
<?php
$rejoan = new people("Rejoanul Alam");
echo "Rejoans full Name: " . $rejoan->get_name();
?>
</body>
</html>
e e
2 u:,
3
:
( ak an! ei' e li
~ (mechanism)
!
:
! ei E6
\\- ^`:
properties e e
1
t
e
k d
ak an!
pg e e E6 , e (encapsulation).e % ak
! s'
(properties) e e Ed
:
k properties e e Ed access modifier , ,3A e ! %21. public
2. private
3. protected
!l , public
<?php
class people {
var $name;
public $height;
protected $social_insurance;
private $pinn_number;
function __construct($people_name) {
$this->name = $people_name;
<i>} </i>
function set_name($new_name) {
$this->name = $new_name;
}
function get_name() {
return $this->name;
}
}
?>
: var o! :
properties
a; (declare) 6 e public , @ ,
@-16:
properties e e
k d
a23
a23-
3 e property
private
a; , 6 @
ei k e 6
3 property
protected
a; , 6 @t ei k e p6:6 k (derived class/ei
kA p k
p6:6 ,o k
3 kA properties e e 2) ei :A k
e 6
ei k e p p6:6 k 3
k
,2
public
Ed6
i
3u skp
3 (
e6 e 6
<?php include("class_lib.php"); ?>
</head>
<body>
<?php
$rejoan = new people("Rejoanul Alam");
echo "Rejoan's full name: " . $rejoan->get_name();
/*
3,6 $pinn_number
private
a; ,2 6i ei
! e ,
(,
pg i
:6
:
*/
echo "Tell me private stuff: " . $rejoan->$pinn_number;
?>
</body>
</html>
\\- ^:
0g e
k d
properties e 6
!o % ei 3A e ! , e nt 6
1.
public
2.
private
3.
protected
%
e ! , ?
ut: e6 % e R :6
3,% D6E kA a ei'
pg , ei
@
e (tg 6
% 6, e u
pk e
a ei'
pg 6 e
6i o ,
<?php
class people {
var $name;
public $height;
protected $social_insurance;
private $pinn_number;
function __construct($people_name) {
$this->name = $people_name;
}
private function get_pinn_number() {
return $this->$pinn_number;
}
}
?>
:
3,6 get_pinn_number() eA private 6i ei
!A @ t
3 k %2,p k
,
33: skp a
o
ei
! 6 ' 6, public
a; 6 ,
\\- ^:
0
4:
t:
t:i4tn
ak an!
pg e i,n (Inheritence) e
~ Dc 3 d % e k a
k/k(
k , , 6
e ,?
ut:e d %
k
! g:, 6 @ % e 6 k D6E 6 'c 3
employee
3,6 employee e @ people/person 6i 6 ei
! e properties
e @ D6E ,2
6?
ei @ as i,n %
!
: e 77 6 % ei
! g:,
2 :A %: kn e d6 ei'
! 6
1. skp % @ e
!( i 6 ,
2.
3,6 %
! g:^6 ,c 6i e a (a) k ^6 ,6 n
!( i ei 6
,a ei' includes() e 6 ,
// 'extends' ei o!A i,n
'
class employee extends people {
function __construct($employee_name) {
}
\\- ^:
0
4:
ta23
ta23-
3,6 employee kA
k people
,2 6i employee kA aA people k
public properties,
! ei k
3(a
6 ei k , 3)
// 'extends' ei o!A i,n
'
class employee extends people {
function __construct($employee_name) {
$this->set_name($employee_name);
}
}
\\- ^:
0g Over r i ddi ng
7 7 (3 i,n , ,) e
!
k
e 6 p ,6
u:,s @ set_name()
!A people k 3 2 6
n 2 employee k 6 ,
% n people k set_name()
! Override 2 employee k ei ei
!A
a;
<?php
class people {
// explicitly adding class properties are optional - but is good practice
var $name;
function __construct($people_name) {
$this->name = $people_name;
}
public function get_name() {
return $this->name;
}
//protected methods and properties restrict access to those elements.
protected function set_name($new_name) {
if (name != "Jimmy Two Guns") {
$this->name = strtoupper($new_name);
}
}
}
// 'extends' ei o!A i,n Dc
'
class employee extends people {
protected function set_name($new_name) {
if ($new_name == "Stefan Sucks") {
$this->name = $new_name;
}
}
function __construct($employee_name) {
$this->set_name($employee_name);
}
}
?>
Alam") {
people::set_name($new_name);
}
}
function __construct($employee_name) {
$this->set_name($employee_name);
}
}
?>
\\- [:
0g overriding a23a23- [
'people::set_name()' eA ei' i
3 6 people k set_name()
!
% d6 %2
3 % parent o!A , 6 k parent k (
k
parent k 3)
: :6
<?php
class people {
// explicitly adding class properties are optional - but is good practice
var $name;
function __construct($people_name) {
$this->name = $people_name;
}
public function get_name() {
return $this->name;
}
//protected methods and properties restrict access to those elements.
protected function set_name($new_name) {
if (name != "Jimmy Two Guns") {
$this->name = strtoupper($new_name);
}
}
}
// 'extends' is the keyword that enables inheritance
03
g:
g:
ak an!
pg e e:
~ ;: %
(e OOPHP e (6 %( %
a , ,
(e OOP
6 % :k6 bd e :6 6, e
!
,
! 6 3 6 6 ak D6E % e : n @
'c
e@ 8/10 A
! D6E e6
: ak % k ( 6 , ,
(2 % 2
OOP e 2 ?4 0pg2
ak an!
pg o D6E e %@ d6a@ ( e ei
! , 23
,ei',,++ i6:
:
o %
e
! 6s6 ei
! m: %! i6:
R , 3 a am! u n
!i ei @ e2ei MVC Structure
!( 3 ( (
@
: n
e
i
3 e
!( ,ei ( 3A ,
! (Model)
u (View)
n (Controller)
( MODEL) :
@ %
!i(i
! e ep D6E 62,ei ep
!( @ ! a @ t p
e p s
!(
3( d iu e
:a
n e e @ o
6 ei'Aee
!i(i e e
e ao
6
3
,!, ,%ee
i
:
KT ( CONTROLLER) :
n p s
!(
3 d ! e u e ( e a
3(3( a
n ! e u
ei ( e
,
!i(i
Oo MVC a
n ! u n s' e t a
n e e
!
,
5.
:
o$ %
p
http://codeigniter.com/downloads/e
!i(i
Oo$A !u! , eA .zip format e
e % e % o$ %! ,
3,6 %
6
:c 6i e ,c
htdocs folder,eA ei
F:\Program Files\xampp\htdocs. eA C Drive e
% 6 C
drive e F :$2 6i F
:c% 6
: ei
C:\Program Files\xampp\htdocs. e e
!u!b 6 (e %b 6)
lA %! a
n
s % @
lA : CodeIgniter.
e
!i(i
lA e system>>application>> config>>config.php iA mk e!
view source
print?
01.|------------------------------------------------------------------------02.| Base Site URL
03.|------------------------------------------------------------------------04.
05.
06.$config['base_url'] = "http://localhost/CodeIgniter/";
07.
08.
09.
10.
11.|------------------------------------------------------------------------12.| Index File
13.|------------------------------------------------------------------------14.
15.
16.$config['index_page'] = "index.php";
17.
18.
19.
20.
21.|------------------------------------------------------------------------22.| Default Language
23.|------------------------------------------------------------------------24.
25.
26.$config['language'] = "english";
27.
28.
29.
30.
31.|------------------------------------------------------------------------32.| Default Character Set
33.|------------------------------------------------------------------------34.
35.
36.$config['charset'] = "UTF-8";
37.
38.
39.
40.
41.|------------------------------------------------------------------------42.| Cache Directory Path
43.|------------------------------------------------------------------------44.
45.
46.$config['cache_path'] = 'http://127.0.0.1/codeigniter/cache/';
47.
48.
49.
50.
51.|------------------------------------------------------------------------52.| Session Variables
53.|------------------------------------------------------------------------54.
55.
56.$config['sess_cookie_name'] = 'ci_session';
57.$config['sess_expiration'] = 7200;
58.$config['sess_encrypt_cookie'] = FALSE;
59.$config['sess_use_database'] = FALSE;
60.$config['sess_table_name'] = 'ci_sessions';
61.$config['sess_match_ip'] = FALSE;
62.$config['sess_match_useragent'] = TRUE;
63.$config['sess_time_to_update'] = 300;
64.
65.
66.
67.
68.|------------------------------------------------------------------------69.| Global XSS Filtering
70.|------------------------------------------------------------------------71.
72.
73.$config['global_xss_filtering'] = FALSE;
74.
75.
76.
77.
78.|------------------------------------------------------------------------79.| Output Compression
80.|------------------------------------------------------------------------81.
82.
83.$config['compress_output'] = TRUE;
84.
85.
86.
87.
88.|------------------------------------------------------------------------89.| Rewrite PHP Short Tags
90.|------------------------------------------------------------------------91.
92.
93.$config['rewrite_short_tags'] = FALSE;
6.
:
o$ %
e
3 config.php iA 2 o database.php e i %2
A
3 e! e ' 6
(
01.$active_group = "default";
02.$active_record = TRUE;
03.
04.
05.$db['default']['hostname']
06.$db['default']['username']
07.$db['default']['password']
08.$db['default']['database']
09.$db['default']['dbdriver']
10.$db['default']['dbprefix']
11.$db['default']['pconnect']
12.$db['default']['db_debug']
13.$db['default']['cache_on']
14.$db['default']['cachedir']
15.$db['default']['char_set']
16.$db['default']['dbcollat']
=
=
=
=
=
=
=
=
=
=
=
=
"localhost";
"root";
"mypassword";
"mydatabase";
"mysql";
"";
TRUE;
TRUE;
FALSE;
"";
"utf8";
"utf8_general_ci";
7.
:
o$ %
@ c % ei Au u %( OOP e OOPHP e Au( e2 6 , e 76
ak an!
pg e
!i(i e a %2 %( Au( % 6o 76
,6 p R %2
!() %: %: 3i
, e ep D6E $e
2 ep D6E
:cei ep @
n e u e , ,e
!
i 6i ! eo
i
F:\Program Files\xampp\htdocs\CodeIgniter\system\application\controllers ei
($ e
helloworld.php i D6E (F e $($ C , %) ei iA
e!
3
!++ e
e class D6E e ' 6
01.<?php
02.class HelloWorld extends Controller{
03.function HelloWorld(){
04.// load controller parent
05.parent::Controller();
06.}
07.function index(){
08.$data['title']='My first application created with Code Igniter';
09.$data['message']='Hello world!';
10.// load 'helloworld' view
11.$this->load->view('helloworld',$data);
12.}
13.}
14.?>
: n a
: e 6 k D6E ,2 e ,c k/p6:6 k/ k
3 k 'Controller'
,2ei 'Controller' kA
!i(i %(
i D6E
2 e ,c
k/n kei n
k 'Controller'
extends o!A : k 'HellowWorld'
,2 6 p6: ,2
(derived).
e parent::Controller() e function index() d ei'
,c 6 n k (Controller e) 3o
e index()
! ()
6 p
6 2
! i ,2 $data
(a) e d6E6 u
p ei
! n ,2
3i
mp 'helloworld.php' loader e k
%2,n e 6 k D6E i ei loader k aA 6
i !l ' %e
!i(i ei
loader kA , u iA
! ! 6 , e
$this->load->view('helloworld',$data);
e c u iA
! e
!( e pass
:
3 bu
:u iA D6E e
F:\Program Files\xampp\htdocs\CodeIgniter\system\application\views ei ($ helloworld.php
e i D6E iA
1.<html>
2.<head>
3.<title><?php echo $title;?></title>
4.</head>
5.<body>
6.<h1><?php echo $message?></h1>
7.</body>
8.</html>