CodeIgniter PHP
ѡ
ѡ .
26 2006 3.1.5 19 2016.
CodeIgniter
PHP .
, , . .
CodeIgniter
CodeIgniter
CodeIgniter MVC (
Models -
Views
Controllers) :
- Models
- Views
- Controllers
(Models) (Views)
CodeIgniter PHP. ڡ PHP. CodeIgniter - . MVC.
ѿ
. ǡ .
CodeIgniter ǡ . (
) . CodeIgniter EllisLab .
CodeIgniter
- MVC ( )
-
-
- (PHP 4 (4.3.+2+ 5
- MySQL (4.1+) MySQLi MS SQL Postgres Oracle SQLite
ODBC. -
-
- ѡ
̡ ʡ ʡ apis -
MVC ֡ .
. ( .
. MVC
). MVC.
- :
. CI
. - : .
CI RSS ajax "" . - : ̡
. CI .
MVC .
- .
- POST ̡
. - .
- .
. ѡ .
1: CodeIgniter
CodeIgniter .
http://www.codeigniter.com/
. 1.70.
2: CodeIgniter
CodeIgniter "CodeIgniter_1.7.0"
ɡ "CI" PHP MySQL.
ߡ :
- CI .
-
ޡ
/ /
/ .
- .
. - .
- .
. - .
- CI ɡ
CI -
. - .
- .
- .
- .
- codeigniter CI .
-
. - .
- CI
. - CI .
. . - CI
- CI.
- .
ʡ . - .
CRUD
.
- CI.
- index.php CI
.
3: CodeIgniter
CI .
.
CI URL . ߡ
/ / / config.php
_url CI.
4: CodeIgniter
CI . http: // localhost / ci /
.
5: CodeIgniter Cont.
. . ߡ ( .)
/ / / database.php . MySQL
" " "" ѡ "".
1
2
3
4
5 |
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "root";
$db['default']['database'] = "helloworld";
$db['default']['dbdriver'] = "mysql"; |
ߡ
.
/ / / autoload.php
" " .
1 |
$autoload['libraries'] = array('database'); |
CI "welcome.php"
/ / . / // routes.php . " ".
1 |
$route['default_controller'] = "Helloworld" |
CI .
/ /
welcome_message.php.
6:
MySQL . " "
SQL phpMyAdmin ( MySQL ).
01
02
03
04
05
06
07
08
09
10
11
12 |
CREATE TABLE `data` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(255) NOT NULL,
`text` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
INSERT INTO `data` (`id`, `title`, `text`) VALUES(1, 'Hello World!', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla
sapien eros, lacinia eu, consectetur vel, dignissim et, massa. Praesent suscipit nunc vitae neque. Duis a ipsum. Nunc a erat. Praesent
nec libero. Phasellus lobortis, velit sed pharetra imperdiet, justo ipsum facilisis arcu, in eleifend elit nulla sit amet tellus.
Pellentesque molestie dui lacinia nulla. Sed vitae arcu at nisl sodales ultricies. Etiam mi ligula, consequat eget, elementum sed,
vulputate in, augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;'); |
7:
CI . PHP
.
helloworld_model.php
/ / .
ݡ .
CI . ǡ .
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 |
<?php
class Helloworld_model extends Model {
function Helloworld_model()
{
// Call the Model constructor
parent::Model();
}
function getData()
{
//Query the data table for every record and row
$query = $this->db->get('data');
if ($query->num_rows() > 0)
{
//show_error('Database is empty!');
}else{
return $query->result();
}
}
}
?> |
8:
֡ . ɡ
http: //localhost/ci/index.php/helloworld/ .
/ / helloworld.php.
ϡ .
ɡ "".
- http: //localhost/ci/index.php/helloworld
. ǡ foo http: //localhost/ci/index.php/helloworld/foo/.
CI URL Ǻ
http://host/codeignitordirectory/ind...class/function
̡ ʡ
. CI ʡ
ʡ ֡ ̡ . ̡
.
- .
01
02
03
04
05
06
07
08
09
10
11
12
13 |
<?php
class Helloworld extends Controller{
function index()
{
$this->load->model('helloworld_model');
$data['result'] = $this->helloworld_model-><span class="sql">getData</span>();
$data['page_title'] = "CI Hello World App!";
$this->load->view('helloworld_view',$data);
}
}
?> |
http: //localhost/ci/index.php/helloworld/ .
9:
.
.
helloworld_view.php / / . ߡ html
.
ʡ "foreach"
.
01
02
03
04
05
06
07
08
09
10
11
12 |
<html>
<head>
<title><?=$page_title?></title>
</head>
<body>
<?php foreach($result as $row):?>
<h3><?=$row->title?></h3>
<p><?=$row->text?></p>
<br />
<?php endforeach;?>
</body>
</html> |
php ɡ
.
10: Ta-da
"http: //localhost/ci/index.php/helloworld/"
.
. CodeIgniter -
index.php URL. .htaccess ѡ .
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ ci/index.php/$1 [L]
config.php // index_page .
1 |
$config['index_page'] = ""; |
CI PHP
. ߡ
/ // config.php TRUE.
1 |
$config['rewrite_short_tags'] = TRUE; |
! CodeIgniter .
:
https://ar.wikipedia.org/wiki/%D9%83...8A%D8%AA%D8%B1
https://code.tutsplus.com/ar/tutoria...iter--net-2634