に、私はしばらくの間、CodeIgniterのを使用して、およびMVCのまともな知識を持ってきた、PHPなど脂肪モデルスキニーコントローラCodeIgniterの
しかし、私はそれはハードファットモデルスキニーコントローラに付着して見つけることですエトス
私はそれについてたくさん見ました。各ファイルに含める擬似コードは含まれていますが、実際の例はありません。 (明白なものが見つからなかった場合は、いくつかの記事にリンクしてください)
私はフォームロジックをモデルに移動するのが難しいと思っています。たとえば、自分のモデルを持っている私の認証システムにカスタムライブラリを使用しています。ユーザーをログインさせるサイトユーザーモデルを作成する必要がありますか?それとも、サイトモデルを作成するだけですか?またはフォームモデルですか?
私を助けるために、誰もこのコントローラをスキンニングする方法について私にアドバイスできますか?私はそれが多くのコードだが、シンプルなポインタが素晴らしいだろうと思う。 (それははるかにリファクタリングされていないが、それは私の方法のいくつかは手に負えなくなっているかの良い例を与える必要がありますので、私はちょうどこのコードを書いて、注意してください。)
public function register()
{
session_start();
if ($this->tf_login->logged_in())
{
redirect('profile');
}
if ($_GET['oauth'] == 'true')
{
$type = $_GET['type'];
try
{
$token = $this->tf_login->oauth($type, '', 'email');
}
catch (TFLoginCSRFMismatchException $e)
{
$this->tf_assets->add_data('error_message', $e->getMessage());
}
catch (TFLoginOAuthErrorException $e)
{
$this->tf_assets->add_data('error_message', $e->getMessage());
}
if ($token)
{
$user_details = $this->tf_login->call('https://graph.facebook.com/me?fields=email,first_name,last_name,username&access_token=' . $token);
$user_details_decoded = json_decode($user_details);
if ($user_details_decoded->email)
{
try
{
$id = $this->tf_login->create_user($user_details_decoded->username,
md5($user_details_decoded->username . time()),
$user_details_decoded->email,
'',
TRUE,
TRUE);
}
catch (TFLoginUserExistsException $e)
{
try
{
if ($this->tf_login->oauth_login($type, $user_details_decoded->email, $token))
{
$this->session->set_flashdata('success_message', 'You have successfully logged in.');
redirect('profile');
}
else
{
$this->session->set_flashdata('error_message', 'An account with these details exists, but currently isn\'t synced with ' . $type . '. Please log in to sync the account.');
}
}
catch (Exception $e)
{
$this->session->set_flashdata('error_message', $e->getMessage());
}
}
catch (TFLoginUserNotCreated $e)
{
$this->tf_assets->add_data('error_message', 'You could not be registered, please try again.');
}
if ($id)
{
$this->tf_login->add_user_meta($id, 'first_name', $user_details_decoded->first_name);
$this->tf_login->add_user_meta($id, 'surname', $user_details_decoded->last_name);
$this->tf_login->sync_accounts($id, $type, $token);
$this->session->set_flashdata('success_message', 'Welcome ' . $this->input->post('first_name', TRUE) . ' ' . $this->input->post('surname', TRUE) . '. Your account has been sucessfully created. You will shortly receive an email with a verification link in.');
redirect('login');
}
}
else
{
$this->session->set_flash_data('error_message', 'You could not be logged in, please try again.');
}
}
// Redirect to clear URL
redirect(current_url());
}
if ($this->form_validation->run() !== FALSE)
{
try
{
$id = $this->tf_login->create_user($_POST['username'], $_POST['password'], $_POST['email'], '', FALSE);
}
catch (Exception $e)
{
$this->tf_assets->add_data('error_message', $e->getMessage());
}
if ($id)
{
$this->tf_login->add_user_meta($id, 'first_name', $_POST['first_name']);
$this->tf_login->add_user_meta($id, 'surname', $_POST['surname']);
if ($this->tf_login->register_verification_email())
{
$this->session->set_flashdata('success_message', 'Welcome ' . $this->input->post('first_name', TRUE) . ' ' . $this->input->post('surname', TRUE) . '. Your account has been sucessfully created. You will shortly receive an email with a verification link in.');
redirect('login');
}
else
{
$this->tf_login->login_user($id);
$this->session->set_flashdata('success_message','Your account has been sucessfully created.');
redirect('profile');
}
}
else
{
$this->tf_assets->add_data('error_message', $this->tf_login->get_errors());
}
}
if (validation_errors())
{
$this->tf_assets->add_data('error_message', validation_errors());
}
$this->tf_assets->set_content('public/register');
$this->tf_assets->add_data('page_title', "Register");
$this->tf_assets->render_layout();
}
感謝あらかじめ!
"脂肪モデル"説教は元のMVCパターンに適用されます。 [これはPHPフレームワークの機能ではありません](http://stackoverflow.com/questions/1549857/simple-php-mvc-framework/1549970#1549970)。それは、CIであなたをあまり良くしません。コントローラをフォーム処理インターフェースとして扱うことは、事実上の問題ではありません。 – mario
[MVCの理解:モデルの "Fat"の概念とコントローラの "Skinny"の概念は何ですか?](http://stackoverflow.com/questions/3109715/understanding-mvc-whats-the-concept-of- fat-on-models-skinny-on-controllers) – Gordon
表示されなかった以前の質問を検索しました。私は読んで、歓声を持っています:) – Toddish