当前位置: 首页>>代码示例>>PHP>>正文


PHP F::i方法代码示例

本文整理汇总了PHP中F::i方法的典型用法代码示例。如果您正苦于以下问题:PHP F::i方法的具体用法?PHP F::i怎么用?PHP F::i使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在F的用法示例。


在下文中一共展示了F::i方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getView

 public function getView($params, $synchrone)
 {
     $form = new Form($this->fields, $params);
     $title = '';
     if ($form->isSubmitting() && Tools::isEmpty($form->getErrors())) {
         $access_key = isset($params['access_key']) && !empty($params['access_key']) ? Tools::saltHash($params['access_key']) : 'NULL';
         // Create Game
         $game = Game::create(F::i('Session')->getMid(), $params['name'], $access_key);
         Tools::redirect('?action=wait_game&game=' . $game->g_id);
     } else {
         // Generate form
         $view = View::setFile('formular', View::HTML_FILE);
         $errors = $form->getErrors();
         // Errors in the filling
         if (!empty($errors)) {
             $view->setSwitch('form_errors', TRUE);
             foreach ($errors as $field => $error) {
                 $view->setGroupValues('form_errors', array('error' => F::i('Lang')->getKey('error_' . $field . '_' . $error)));
             }
         }
         $view->setValue('form', $form->getHTML(F::i('Lang')->getKey('Create'), '#', 'POST', 'tabbed_form'));
         $title = F::i('Lang')->getKey('title_new_game');
     }
     return parent::setBody($view, $title);
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:25,代码来源:new_game.php

示例2: getView

 public function getView($params, $synchrone)
 {
     try {
         $game = new Game($params['game']);
         if (!$game->isIn(F::i('Session')->getMid())) {
             throw new Exception('Not In');
         }
     } catch (Exception $e) {
         // Get Out!
         die('Oust !');
     }
     $view = View::setFile('map', View::HTML_FILE);
     /**
      * Links
      */
     $result = F::i(_DBMS_SYS)->query('SELECT cou1.cou_name AS cou1, cou2.cou_name AS cou2 FROM !prefix_adjacent a, !prefix_countries cou1, !prefix_countries cou2 WHERE a.cou_id1 = cou1.cou_id AND a.cou_id2 = cou2.cou_id');
     while (($obj = $result->getObject()) != NULL) {
         $view->setGroupValues('adjacents', array('from' => $obj->cou1, 'to' => $obj->cou2));
     }
     $view->setValue('game', $game->g_id);
     $view->setValue('mode', isset($params['mode']) ? $params['mode'] : 'owner');
     $view->setValue('confirmed', $game->getPlayer(F::i('Session')->getMid())->p_ready);
     $view->setValue('step', $game->g_step);
     $view->setValue('m_id', F::i('Session')->getMid());
     return parent::setBody($view, '', TRUE);
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:26,代码来源:play.php

示例3: getView

 public function getView($params, $synchrone)
 {
     try {
         $game = new Game($params['game']);
         if ($game->g_step > 0) {
             throw new Exception('Game already launched');
         }
         if (!$game->isIn(F::i('Session')->getMid())) {
             throw new Exception('You are not in this game');
         }
     } catch (Exception $e) {
         // Get Out!
         die('Oust ! : ' . $e);
     }
     if ($synchrone) {
         $view = View::setFile('wait_game', View::HTML_FILE);
         $view->setValue('u_js', '?action=wait_game&game=' . $game->g_id);
         $view->setValue('u_leave', '?action=leave_game&game=' . $game->g_id);
         $view->setValue('game', stripslashes($game->g_name));
         if ($game->m_id == F::i('Session')->getMid()) {
             $view->setSwitch('creator', TRUE);
             $view->setValue('u_launch', '?action=launch_game&game=' . $game->g_id);
         }
         return parent::setBody($view, F::i('Lang')->getKey('title_wait_game'));
     } else {
         $view = View::setFile('wait_game', View::JSON_FILE);
         $players = $game->getPlayers();
         for ($i = 0; $i < count($players); $i++) {
             $view->setGroupValues('players', array('name' => $players[$i]->m_login, 'color' => $players[$i]->col_code, 'col_name' => $players[$i]->col_name));
         }
         return $view->getContent();
     }
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:33,代码来源:wait_game.php

示例4: getView

 public function getView($params, $synchrone)
 {
     try {
         $game = new Game($params['game']);
         if ($game->g_step > 0) {
             throw new Exception('Game already launched');
         }
         if ($game->m_id != F::i('Session')->getMid()) {
             throw new Exception('You are not the owner of this game !');
         }
         if ($game->getNumPlayers() == 1) {
             throw new Exception('Cannot launch a game with a single player');
         }
     } catch (Exception $e) {
         // Get Out!
         die('Oust !');
     }
     // Give countries to players
     /*
      * 42 countries
      * /2 => 21
      * /3 => 14
      * /4 => 10.5 (10 + 2)
      * /5 => 8.4 (8 + 2)
      * /6 => 7
      * /7 => 6
      * /8 => 5.25 (5 + 2)
      * /9 => 4.67 (4 + 6)
      * /10 => 4.2 (4 + 2)
      */
     $players = $game->getPlayers();
     $count_players = count($players);
     $result = F::i(_DBMS_SYS)->query('SELECT cou_id FROM !prefix_countries');
     $countries = array();
     while (($obj = $result->getObject()) != NULL) {
         $countries[] = $obj->cou_id;
     }
     $count_countries = count($countries);
     $countries_per_player = intval($count_countries / $count_players);
     shuffle($countries);
     $lands = array_chunk($countries, $countries_per_player);
     // What to do with the last countries ? Give...
     $remaining = array();
     if (count($lands) > $count_players) {
         $remaining = $lands[$count_players];
     }
     shuffle($players);
     for ($i = 0; $i < count($remaining); $i++) {
         $lands[$i][] = $remaining[$i];
     }
     // Save and Go to step 1
     for ($i = 0; $i < $count_players; $i++) {
         for ($j = 0; $j < count($lands[$i]); $j++) {
             F::i(_DBMS_SYS)->exec('INSERT INTO !prefix_lands (g_id, cou_id, m_id) VALUES (?, ?, ?)', array($params['game'], $lands[$i][$j], $players[$i]->m_id));
         }
     }
     $game->nextStep();
     Tools::redirect('?action=play&game=' . $params['game']);
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:59,代码来源:launch_game.php

示例5: getView

 public function getView($params, $synchrone)
 {
     $form = new Form(self::getFields(), $params);
     $view = View::setFile('chatbox', View::JSON_FILE);
     $fields = Chatbox::getFields();
     if (F::i('Session')->isConnected()) {
         $fields['name']['disabled'] = TRUE;
     }
     $errors = $form->getErrors();
     if (!Tools::isEmpty($errors)) {
         foreach ($errors as $field => $msg) {
             $view->setGroupValues('error', array('field' => $field, 'errmsg' => $msg));
         }
     }
     // If Submitting
     if ($form->isSubmitting() && Tools::isEmpty($form->getErrors())) {
         // TODO Sauvegarde du pseudo en cookie
         // Enregistrement des données
         if (F::i('Session')->isConnected()) {
             $m_name = '';
         } else {
             $m_name = $params['name'];
             self::setNickname($m_name);
         }
         F::i(_DBMS_SYS)->exec('INSERT INTO !prefix_chatbox_messages (m_id, m_name, mes_content) VALUES (?, ?, ?)', array(F::i('Session')->getMid(), $m_name, $params['content']));
         // Et sortie
         return;
     }
     // Recuperation des derniers messages
     $sql = 'SELECT mes.m_name, m.m_login, mes.m_id, mes_content, UNIX_TIMESTAMP(mes_date) AS mes_date FROM !prefix_chatbox_messages mes, !prefix_members m WHERE m.m_id = mes.m_id';
     $array = array();
     // si une date est donnée, tous les messages depuis cette date
     if (isset($params['since'])) {
         $sql .= ' AND mes_date > FROM_UNIXTIME(?)';
         $array[] = $params['since'];
     }
     // sinon, limiter à _LIMIT_LAST_CHATBOX messages
     $sql .= ' ORDER BY mes_date DESC';
     if (!isset($params['since'])) {
         $sql .= ' LIMIT ?';
         $array[] = _LIMIT_LAST_CHATBOX;
     }
     // Generation d'un pseudo si non connecté et pseudo non fourni
     // Si connecté, verouiller le pseudo
     $result = F::i(_DBMS_SYS)->query($sql, $array);
     // Recover messages and switch the order to get the last _LIMIT_LAST_CHATBOX messages but the last at the end.
     $messages = array();
     for ($i = 0; $i < $result->getNumRows(); $i++) {
         $obj = $result->getObject();
         $messages[] = array('author_mid' => $obj->m_id, 'author_name' => $obj->m_id == _ID_VISITOR ? $obj->m_name : $obj->m_login, 'content' => htmlentities($obj->mes_content, ENT_QUOTES, 'UTF-8', TRUE), 'date' => $obj->mes_date);
     }
     $messages = array_reverse($messages);
     for ($i = 0; $i < count($messages); $i++) {
         $view->setGroupValues('message', $messages[$i]);
     }
     return $view->getContent();
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:57,代码来源:chatbox.php

示例6: getView

 public function getView($params, $synchrone)
 {
     try {
         if (!isset($params['game'])) {
             throw new Exception('No Game given');
         }
         $game = new Game($params['game']);
     } catch (Exception $e) {
         // Get Out!
         die('Oust !');
     }
     $params['mode'] = isset($params['mode']) ? $params['mode'] : '';
     switch ($params['mode']) {
         case 'continents':
             $mode = 'continents';
             break;
         case 'owner':
         default:
             $mode = 'owner';
     }
     $view = View::setFile('map', View::SVG_FILE);
     /**
      * Territories
      */
     $result = F::i(_DBMS_SYS)->query('SELECT cou.cou_name, cou.cou_troops_x, cou.cou_troops_y, cou.cou_d, con.con_name, l.m_id, l.l_strength FROM !prefix_continents con, !prefix_countries cou, !prefix_lands l WHERE l.g_id = ? AND l.cou_id = cou.cou_id AND cou.con_id = con.con_id', array($game->g_id));
     while (($obj = $result->getObject()) != NULL) {
         $view->setGroupValues('territories', array('cou_name' => $obj->cou_name, 'con_name' => $obj->con_name, 'cou_d' => $obj->cou_d, 'm_id' => $obj->m_id, 'troops' => $obj->l_strength, 'troops_x' => $obj->cou_troops_x, 'troops_y' => $obj->cou_troops_y));
     }
     /**
      * Display Mode
      */
     if ($mode == 'owner') {
         $result = F::i(_DBMS_SYS)->query('SELECT p.m_id, m.m_login, col.col_code FROM !prefix_players p, !prefix_members m, !prefix_colors col WHERE p.m_id = m.m_id AND p.col_id = col.col_id AND p.g_id = ?', array($game->g_id));
         while (($obj = $result->getObject()) != NULL) {
             $view->setGroupValues('styles', array('style_name' => 'g.player_' . $obj->m_id, 'style_code' => 'fill: #' . $obj->col_code));
             /**
              * Legend
              */
             $view->setGroupValues('legend', array('id' => 'legend_player_' . $obj->m_id, 'text' => $obj->m_login, 'col_code' => $obj->col_code));
         }
     } else {
         if ($mode == 'continents') {
             // con_id = col_id... Just to have a color but normaly, no link lol
             $result = F::i(_DBMS_SYS)->query('SELECT con.con_name, con.con_id, col.col_code FROM !prefix_continents con, !prefix_colors col WHERE con.con_id = col.col_id');
             while (($obj = $result->getObject()) != NULL) {
                 $view->setGroupValues('styles', array('style_name' => '.' . $obj->con_name, 'style_code' => 'fill: #' . $obj->col_code));
                 /**
                  * Legend
                  */
                 $view->setGroupValues('legend', array('class' => 'legend_continent_' . $obj->con_id, 'text' => $obj->con_name, 'col_code' => $obj->col_code));
             }
         }
     }
     return $view->getContent();
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:55,代码来源:map.php

示例7: getView

 public function getView($params, $synchrone)
 {
     include_once _MODEL_DIR . '/chatbox.php';
     $chatbox = new Form(Chatbox::getFields(), array('name' => Chatbox::getNickname()));
     $login = F::i('Session')->getUsername();
     // Display Index page...
     $view = View::setFile('index', View::HTML_FILE);
     $view->setValue('u_chatbox', '?action=chatbox');
     $view->setValue('chatbox_form', $chatbox->getHTML('', '?action=chatbox', 'ajax', 'chatbox_form', 'cron.socket', 'clear_chatbox'));
     $view->setValue('login', $login);
     return parent::setBody($view, F::i('Lang')->getKey('title_index'));
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:12,代码来源:index.php

示例8: getView

 public function getView($params, $synchrone)
 {
     try {
         $game = new Game($params['game']);
         if (!$game->isIn(F::i('Session')->getMid())) {
             throw new Exception('You are not part of this Game');
         }
     } catch (Exception $e) {
         // Get Out!
         die('Oust !');
     }
     $game->reject(F::i('Session')->getMid());
     Tools::redirect('?action=current_games');
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:14,代码来源:leave_game.php

示例9: check

 public static function check($action, $params = array())
 {
     Factory::include_class($action);
     $privacy = defined($action . '::PRIVACY') ? constant($action . '::PRIVACY') : _PRIVACY_ALL;
     if (!F::i('Session')->canAccess($privacy)) {
         if (!F::i('Session')->isConnected()) {
             $params['action'] = $action;
             Tools::redirect('?' . http_build_query(array('action' => 'connect', 'redirect' => rawurlencode('?' . http_build_query($params)))));
         } else {
             return Model::showError('not allowed');
         }
     }
     $instance = F::i($action, '', 'Model');
     F::i('Lang')->importLangFile($action);
     return $instance->getView($params, !(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:16,代码来源:Controller.php

示例10: getView

 public function getView($params, $synchrone)
 {
     try {
         if (!isset($params['game'])) {
             throw new Exception('No Game given');
         }
         $game = new Game($params['game']);
         if ($game->g_step == 0) {
             throw new ModelException('Game not launched');
         }
         if (!$game->isIn(F::i('Session')->getMid())) {
             throw new ModelException('You can\'t play : you are not in the game !');
         }
         $sql = array();
         // Check all the actions
         $params['act'] = isset($params['act']) ? $params['act'] : array();
         for ($i = 0; $i < count($params['act']); $i++) {
             list($from, $to, $strength, $priority) = explode(';', $params['act'][$i]);
             if ($strength <= 0) {
                 throw new ModelException('Strength positive !');
             }
             if (!in_array($priority, $GLOBALS['priorities'])) {
                 throw new ModelException('Priority Unavailble !');
             }
             // Check actions
             $result = F::i(_DBMS_SYS)->query('SELECT c1.cou_id AS cou_id1, c1.cou_name AS cou_from, c2.cou_id AS cou_id2, c2.cou_name AS cou_to FROM !prefix_adjacent a LEFT JOIN !prefix_countries c1 ON a.cou_id1 = c1.cou_id LEFT JOIN !prefix_countries c2 ON a.cou_id2 = c2.cou_id WHERE (c1.cou_name = ? AND c2.cou_name = ?) OR (c1.cou_name = ? AND c2.cou_name = ?)', array($from, $to, $to, $from));
             if ($result->getNumRows() != 0) {
                 $obj = $result->getObject();
                 // Check capacity...
                 // TODO
                 $from_id = $obj->cou_from == $from ? $obj->cou_id1 : $obj->cou_id2;
                 $to_id = $obj->cou_to == $to ? $obj->cou_id2 : $obj->cou_id1;
                 $sql[] = array('INSERT INTO !prefix_actions (g_id, cou_from, cou_to, a_strength, a_priority) VALUES (?, ?, ?, ?, ?)', array($game->g_id, $from_id, $to_id, $strength, $priority));
             }
         }
         // Confirm the player
         F::i(_DBMS_SYS)->exec('UPDATE !prefix_players SET p_ready=1 WHERE m_id=? AND g_id=?', array(F::i('Session')->getMid(), $game->g_id));
         // Insert Actions
         F::i(_DBMS_SYS)->mexec($sql);
     } catch (ModelException $e) {
         // Get Out!
         die('Oust ! : ' . $e->getMessage());
     }
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:44,代码来源:act.php

示例11: getView

 public function getView($params, $synchrone)
 {
     try {
         if (!isset($params['game'])) {
             throw new Exception('No Game given');
         }
         $game = new Game($params['game']);
         if (!$game->isIn(F::i('Session')->getMid())) {
             throw new Exception('Not In');
         }
         if (!isset($params['step']) || empty($params['step'])) {
             throw new Exception('Need step');
         }
         $view = View::setFile('confirm', View::JSON_FILE);
         if ($params['step'] == $game->g_step + 1) {
             // If all players ready
             $result = F::i(_DBMS_SYS)->query('SELECT m_id FROM !prefix_players WHERE g_id=? AND p_ready=0', array($game->g_id));
             if ($result->getNumRows() == 0) {
                 // If somebody is solving the game
                 // Dangerous Part so ask the database to have the LAST info
                 $result = F::i(_DBMS_SYS)->query('SELECT g_resolving FROM !prefix_games WHERE g_id=?', array($game->g_id));
                 if ($result->getObject()->g_resolving == 0) {
                     // Let's Solve !
                     F::i(_DBMS_SYS)->mexec(array(array('UPDATE !prefix_games SET g_resolving=1 WHERE g_id=?', array($game->g_id)), array('CALL PROC_SOLVE_ATTACKS(?)', array($game->g_id)), array('UPDATE !prefix_players SET p_ready=0 WHERE g_id=?', array($game->g_id)), array('UPDATE !prefix_games SET g_step=g_step+1 WHERE g_id=?', array($game->g_id)), array('UPDATE !prefix_games SET g_resolving=0 WHERE g_id=?', array($game->g_id))));
                 }
                 $view->setValue('confirm', 1);
             } else {
                 $view->setValue('confirm', 0);
             }
         } else {
             if ($params['step'] == $game->g_step) {
                 $view->setValue('confirm', 1);
             } else {
                 throw new Exception('Not a valid step');
             }
         }
     } catch (Exception $e) {
         // Get Out!
         die('Oust ! : ' . $e->getMessage());
     }
     return $view->getContent();
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:42,代码来源:solve.php

示例12: getView

 public function getView($params, $synchrone)
 {
     // Get all the games of the player
     $result = F::i(_DBMS_SYS)->query('SELECT g.g_id, g_name, g_step, COUNT(*) AS g_total_players, TIMESTAMPDIFF(HOUR, g_start, NOW()) AS lifetime, m_login AS g_owner FROM !prefix_members m, !prefix_players AS p, !prefix_games AS g, !prefix_players AS p2 WHERE p.m_id = ? AND g.m_id = m.m_id AND p.g_id = g.g_id AND g.g_id = p2.g_id GROUP BY g.g_id', array(F::i('Session')->getMid()));
     $view = View::setFile('list_games', View::HTML_FILE);
     $view->setValue('form', '');
     if ($result->getNumRows() == 0) {
         $view->setSwitch('no_games', TRUE);
     }
     for ($i = 0; $i < $result->getNumRows(); $i++) {
         $obj = $result->getObject();
         if ($obj->g_step == 0) {
             $link = '?action=wait_game&game=' . $obj->g_id;
             $name = '<span style="font-style: italic;">' . $obj->g_name . '</span>';
         } else {
             $link = '?action=play&game=' . $obj->g_id;
             $name = '<span style="font-weight: bold;">' . $obj->g_name . '</span>';
         }
         $view->setGroupValues('games', array('link' => $link, 'name' => $name, 'total_players' => $obj->g_total_players, 'owner' => $obj->g_owner, 'lifetime' => $obj->lifetime));
     }
     return parent::setBody($view, F::i('Lang')->getKey('title_current_games'));
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:22,代码来源:current_games.php

示例13: getView

 public function getView($params, $synchrone)
 {
     $form = new Form($this->fields, $params);
     if ($form->isSubmitting() && Tools::isEmpty($form->getErrors())) {
         // Register
         $salt = Tools::generateSalt();
         $password = Tools::saltHash($params['password'], $salt);
         $error = FALSE;
         try {
             F::i(_DBMS_SYS)->exec('INSERT INTO !prefix_members (m_login, m_password, m_email, m_salt, m_auth) VALUES (?, ?, ?, ?, ?)', array($params['login'], $password, $params['email'], $salt, _AUTH_MEMBER));
         } catch (DBMSError $e) {
             // Login already given
             $error = TRUE;
         }
         if (!$error) {
             $view = View::setFile('info', View::HTML_FILE);
             $view->setValue('L_message', F::i('Lang')->getKey('register_successful'));
             $view->setValue('U_ok', '?');
             F::i('Session')->connect($params['login'], $params['password']);
         } else {
             $view = View::setFile('error', View::HTML_FILE);
             $view->setValue('l_message', F::i('Lang')->getKey('login_taken'));
             $view->setValue('u_ok', '?');
         }
     } else {
         $view = View::setFile('formular', View::HTML_FILE);
         $errors = $form->getErrors();
         // Errors in the filling
         if (!empty($errors)) {
             $view->setSwitch('form_errors', TRUE);
             foreach ($errors as $field => $error) {
                 $view->setGroupValues('form_errors', array('error' => F::i('Lang')->getKey('error_' . $field . '_' . $error)));
             }
         }
         $view->setValue('form', $form->getHTML(F::i('Lang')->getKey('register'), '#', 'POST', 'tabbed_form'));
     }
     return parent::setBody($view);
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:38,代码来源:register.php

示例14: setBody

 protected static final function setBody(ViewItem $content, $title = '', $short = FALSE)
 {
     include_once _MODEL_DIR . '/connect.php';
     $form = new Form(Connect::getFields());
     if ($short) {
         $view = View::setFile('short_header');
         $view->setValue('SITE_TITLE', (!empty($title) ? $title . ' &laquo; ' : '') . _SITE_TITLE);
     } else {
         $view = View::setFile('header');
         $view->setValue('SITE_TITLE', (!empty($title) ? $title . ' &laquo; ' : '') . _SITE_TITLE);
         $view->setValue('L_WELCOME', sprintf(F::i('Lang')->getKey('Welcome_Explain'), F::i('Session')->isConnected() ? F::i('Session')->getUsername() : F::i('Lang')->getKey('Guest')));
         $view->setValue('FORM_CONNECT', $form->getHTML('', '?action=connect', 'POST'));
     }
     // Static Switches
     $view->setStaticSwitch('debug', _DEBUG);
     $view->setStaticSwitch('is_guest', !F::i('Session')->isConnected());
     $view->setStaticSwitch('is_member', F::i('Session')->getAuth() >= _AUTH_MEMBER);
     $view->setStaticSwitch('is_admin', F::i('Session')->getAuth() >= _AUTH_ADMIN);
     $header = $view->getContent();
     $view = View::setFile('footer');
     $view->setValue('BENCHMARK', F::i('Benchmark')->getTotal());
     $footer = $view->getContent();
     return $header . $content->getContent() . $footer;
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:24,代码来源:Model.php

示例15: generate

 /**
  * Generate a form with an array of fields
  * array(
  * 	NAME => array(
  *		'type' => TYPE,
  * 		'value' => DEFAULT_VALUE,
  * 		'check' => 'check',
  * 		'params' => array(
  * 			'regex' => REGEX (for CHECK == REGEX)
  * 			'maxlength' => MAXLENGTH ()
  * 		)
  *	)
  * );
  *
  * @param Array $fields
  * @param Array $params
  * @param String $title
  * @param String $target
  * @param String $method (GET|POST)
  * @return String HTML Form to display and to use ^^
  */
 private static function generate($fields, $params, $title, $target, $method, $checks, $style, $callback, $aftersubmit)
 {
     $string = '';
     $title = !empty($title) ? '<legend>' . htmlentities($title) . '</legend>' : '';
     assert('!empty($fields)');
     foreach ($fields as $name => $field) {
         if (isset($params[$name])) {
             $field_value = $params[$name];
         } else {
             if (isset($field['value'])) {
                 $field_value = $field['value'];
             } else {
                 $field_value = '';
             }
         }
         $field_key = isset($field['name']) && F::i('Lang')->isKey($field['name']) ? $field['name'] : (F::i('Lang')->isKey($name) ? $name : NULL);
         $field_name = !is_null($field_key) ? F::i('Lang')->getKey($field_key) : $name;
         $field_explain = !is_null($field_key) && F::i('Lang')->isKey($field_key . '_explain') ? '<p class="field_explain">' . F::i('Lang')->getKey($field_key . '_explain') . '</p>' : '';
         $field_check = isset($field['check']) ? $field['check'] : '';
         $field_params = isset($field['params']) ? $field['params'] : '';
         $field_type = $field['type'];
         $field_error = isset($checks[$field_key]) && !empty($checks[$field_key]) ? 'field_error' : '';
         $field_disabled = isset($field['disabled']) ? 'disabled=true' : '';
         // TODO :
         // Style
         // width:
         // disable:
         // height:
         // maxlength:
         $string .= '<p>' . sprintf(self::$formats[$field_type], $name, $field_name, $field_check, $field_params, $field_value, $field_error, $field_disabled) . '</p>';
     }
     //$string .= '<input type="reset" name="reset" id="__reset" value="'.F::i('Lang')->getKey('reset').'" />';
     $string .= '<input type="submit" name="submit" id="__submit" value="' . F::i('Lang')->getKey('submit') . '" />';
     $check = '<input type="hidden" name="__check_hash" value="' . self::hash($fields) . '" />';
     return '<fieldset class="' . $style . '">' . $title . '<form class="' . $style . '" action="' . $target . '" method="' . $method . '" callback="' . $callback . '" aftersubmit="' . $aftersubmit . '">' . $string . $check . '</form></fieldset>';
 }
开发者ID:Korko,项目名称:RiskOnline,代码行数:57,代码来源:Form.php


注:本文中的F::i方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。