2014年10月22日 星期三

CodeIgniter 學習筆記(一)

一、主要放網頁目錄application,大部分修改的地方
設定database
路徑: application/config/database.php
m : model
v : views
c : controller

二、CI提供的class system

三、流程

注意:
每個控制器都是一個類 class,每個class裡面的function都是一個頁面。

業務流程:
localhost/index.php/welcome/index
入口 > 控制器 > 方法 > 參數
如果刪除welcome 或者是index, 還是會導向index.php, 原因是因為application/config/routes.php 內的設定

四、控制器
1. 控制器是什麼?
    類文件
2. 如何建立控制器?
    在application\controllers下建立文件\   >> class必須大寫開頭  >> 繼承 CI_Controller
3. create function
    create one function()   >  default is function index()
4. url如何傳遞參數給方法

沒有傳遞參數寫法
class Hello extends CI_Controller {
  function sayhello(){
    echo 'hello world';
  }
}
http://localhost/index.php/hello/sayhello

 
傳遞參數寫法
class Hello extends CI_Controller {
   function sayhello($name){
     echo $name.'hello world';
   }
}
ERROR -> http://localhost/index.php/hello/sayhello
OK -> http://localhost/index.php/hello/sayhello/woo

沒有留言:

張貼留言