almost 5 years ago

CodeIgniter/application/controllers/account.php

Controllers 控制所有的Method

<?php
class Account extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('account_model');
        $this->load->library('table');
    }

    public function index()
    {
        $this->load->helper('form');
        
        $data['title'] = 'Account';
        $this->load->view('account/apply');
    }
    public function ok()
    {
        $this->load->view('account/success');
        $this->account_model->apply_account();
    }
} 

定義每一個Method要分別做甚麼:

  • index(主畫面):load apply 這個view進來
  • ok:當 apply 按下 Submit button 後會啟動的method,load success這個view,並將資料存到資料庫

CodeIgniter/application/views/account/apply.php

Views 掌管看到的前端 html、css

<?php echo form_open('account/ok') ?>
<fieldset>
    <legend>申請資料</legend>
    <label for="account">Account</label> 
    <input type="text" name="account" /><br />

    <label for="country">Country</label> 
    <select name="country">
        <option>台灣</option>
        <option>中國</option>
        <option>香港</option>
    </select>
    <br />
    <input type="checkbox" name="agree" />
    已閱讀相關資料<br />
    <br />

    <button type="submit" name="submit" class="btn">Apply</button>
</fieldset>
</form>

form_open 會在按下submit button後,導引到ok的method
原理:在原本網址(此例為 CodeIgniter/index.php/ ) 後加上 account/ok

CodeIgniter/application/views/account/success.php
success

CodeIgniter/application/config/config.php

$config['url_suffix'] = '.py';
=> $config['url_suffix'] = '';


demo

瀏覽器輸入 localhost/CodeIgniter/index.php/account/index

(可以只省略打localhost/CodeIgniter/index.php/account/ 意思是一樣的)

我的CI目錄是在 AppServ/www/CodeIgniter 之中 (環境為Win7)
CodeIgniter 底下主要有

  • application/
  • system/
  • user_guide/
  • welcome/
  • index.php
  • license.txt
← [入手] j5Create Ultra Station (JUD500)、Timbuk2 D-Lux Messenger (S) CI - 簡潔的網址 用 mod_rewrite 去掉 index.php →
 
comments powered by Disqus