close

1.JPG

CodeIgniter 是一套小巧但功能强大的 PHP 框架,做為一個簡單而“優雅”的工具包,它是一套專為 PHP 開發者建立功能完善的 Web 應用程序,如果你是一個使用虛擬主機,並且為客戶所要求的期限而煩惱的開發人員,如果你已经厭倦那些難而且效率不高的框架,官方網站連結如下,

CodeIgniter 繁體中文

2.JPG

下載與解完壓縮完成如下,

3.JPG

接下來會把解完壓所的CodeIgniter-3.1.6放置Docker路徑

\Kitematic\apache-php56\var\www

Docker安裝Apache-php5.6與Mariadb可參考[Docker學習筆記]Apache-php5.6與Mariadb安裝

16.JPG

再來更改Apache-php5.6檔案路徑,在Settins->Volumes更改路徑為

\Kitematic\apache-php56\var\www\CodeIgniter-3.1.6

17.JPG

啟動Apache-php5.6點擊右方紅框,就會出現網頁,

18.JPG

能出現以下畫面就代表套用成功

19.JPG

接下來設置資料庫,點擊EXEC

11.JPG

進入後輸入指令

mysql -u root -p

接下來輸入密碼進入即可

新增資料庫(ci_database)輸入指令

create database ci_database;

新增完成後查看新增結果,輸入指令

show database;

12.JPG

建立測試表,輸入指令

create table test_table(
id int NOT NULL AUTO_INCREMENT,
message text,
createtime timestamp,
primary key (id)
);

20.JPG

新增測試資料,輸入指令

INSERT INTO test_table (message)

VALUES ("CI create success!!");

21.JPG

資料庫與測試資料建立完成後,回到CodeIgniter-3.1.6,到路徑

\Kitematic\apache-php56\var\www\CodeIgniter-3.1.6\application\config

開啟database.php,如下所示,

9.JPG

下面是設置資料庫的各個項目,要了解各個項目可至這了解

https://www.codeigniter.com/userguide3/database/configuration.html

14.JPG

設置完成如下所示,

13.JPG

CodeIgniter-3.1.6資料庫設置完成後,接下來要新增三隻測試程式,

\Kitematic\apache-php56\var\www\CodeIgniter-3.1.6\application\controllersTest.php,程式如下,

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Test extends CI_Controller {

    public function __construct()
    {
        /* 擴充父類別的建構函數 */
        parent::__construct(); 
        /* 載入test_model */
        $this->load->model('test_model');
        /* 載入url_helper */
        $this->load->helper('url_helper');               
    }
    
    public function index()
    {
        /* 取得test_model中的get_test資料庫資料 */
        $array = $this->test_model->get_test();
        /* 擷取message資料 */
        $data['test'] = $array[0]['message'];
        /* 送到test_message.php顯示 */
        $this->load->view('test_message', $data);        
    }
}

\Kitematic\apache-php56\var\www\CodeIgniter-3.1.6\application\modelsTest_model.php,程式如下,

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Test_model extends CI_Model {

    public function __construct()
    {
        /* 載入料庫 */
        $this->load->database();       
    }
    
    public function get_test()
    {
        /* 取得test_table全部資料 */
        $query = $this->db->get('test_table');
        /* 以陣列方式回傳到controllers */
        return $query->result_array();           
    }    
}

 

\Kitematic\apache-php56\var\www\CodeIgniter-3.1.6\application\viewsTest_message.php,程式如下,

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Test to CodeIgniter</title>

    <style type="text/css">

    </style>
</head>
<body>

<h2><?php echo $test;?></h2>

</body>
</html>

最後到\Kitematic\apache-php56\var\www\CodeIgniter-3.1.6\application\config中的routes.php,

23.JPG

修改default_controller,如下所示,

24.JPG

以上完成後進入網頁呈現如下結果就成功啦

22.JPG

arrow
arrow

    鄭智遠 發表在 痞客邦 留言(0) 人氣()