網站開發基本教學
  • Introduction
  • 基本元素
  • Nginx (伺服器)
    • Config 基本配置
    • Regular Expression 正規化
  • Codeigniter (程式語言框架)
    • Config
    • Controller
    • View
    • Model
      • Question
    • Helper
    • MVC
  • MySQL
Powered by GitBook
On this page

Was this helpful?

  1. Codeigniter (程式語言框架)
  2. Model

Question

這段程式碼還可以重構嗎?

if ($query = $this->database->get(
    'game',    // 資料表名稱
    array(    // where
        'game.id' => $game_id,
    ),
    array(),    // order_by
    array(),    // join
    array(    // select
        'game.id',    // 遊戲序號
        'game.name',    // 遊戲名稱
    ),
    1
)) {
    ...
    ...
    ...
}

這樣是否比較容易閱讀?

$result = $this->database->from('game')
                        ->select('id, name')
                        ->where('id', $game_id)
                        ->get();

if ($result) {
    ...
    ...
}
PreviousModelNextHelper

Last updated 5 years ago

Was this helpful?