本文整理匯總了PHP中Model_Table::forge方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model_Table::forge方法的具體用法?PHP Model_Table::forge怎麽用?PHP Model_Table::forge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Model_Table
的用法示例。
在下文中一共展示了Model_Table::forge方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: action_edit
/**
* Действие дял редактирования сезона (соревнования)
*
* @param int $id
*/
public function action_edit($id = null)
{
is_null($id) and \Response::redirect_back('admin/competitions/seasons');
if (!($season = \Model_Season::find($id, array('related' => array('teams'))))) {
\Session::set_flash('error', 'Could not find Season #' . $id);
\Response::redirect_back('admin/competitions/seasons');
}
$val = \Model_Season::validate('edit');
if ($val->run()) {
$season->value = \Input::post('value');
unset($season->teams);
if (\Input::post('teams')) {
foreach (\Input::post('teams') as $item) {
$season->teams[] = \Model_Team::find($item);
}
}
if ($season->has_table == 1 and \Input::post('has_table') == 0) {
$table = \Model_Table::find('first', array('where' => array(array('season_id', '=', $season->id))));
if ($table) {
$table->delete();
}
$season->has_table = 0;
}
// Если нужно также создать таблицу
if ($season->has_table == 0 and \Input::post('has_table') == 1) {
$season->has_table = 1;
// Массив таблицы результатов
$arr = array();
$i = 1;
foreach ($season->teams as $item) {
$arr[] = array('id' => $item->id, 'place' => $i, 'name' => $item->value, 'games' => 0, 'wins' => 0, 'draws' => 0, 'loss' => 0, 'goals_in' => 0, 'goals_out' => 0, 'goals_out' => 0, 'points' => 0);
$i++;
}
$season->table = \Model_Table::forge(array('results_json' => json_encode($arr), 'show_on_main' => 0));
}
if ($season->save()) {
\Session::set_flash('success', 'Сезон (соревнование) обновлен(о).');
\Response::redirect_back('admin/competitions/seasons');
} else {
\Session::set_flash('error', 'Could not update Season #' . $id);
}
} else {
if (\Input::method() == 'POST') {
$season->value = $val->validated('value');
$season->has_table = $val->validated('has_table');
\Session::set_flash('error', $val->error());
}
$this->template->set_global('season', $season, false);
// Все команды
$this->template->set_global('teams', \Model_Team::get_teams_for_select(), false);
// Массив id команд сезона
$season_teams = array();
foreach ($season->teams as $item) {
$season_teams[] = $item->id;
}
$this->template->set_global('season_teams', $season_teams, false);
}
$this->template->content = \View::forge('competitions/seasons/edit');
}