CodeIgniter を使用したコードは次のとおりです。
私が遭遇する問題:
コントローラーにはいくつかの関数呼び出しビューがあり、分離されていますが、ロジック自体と非常に近いため、コントローラーが結果を表示するためにJSONまたはXMLで返すように変更すると、非常に問題が発生するようです。
多くの方法のように見えますが、それぞれが別のものに依存しています。
コードを追跡するのは難しいと思います。
いくつかの提案をお願いします。※コントローラクラスのみですのでご注意ください。読み込みビューは実際にはビューのデータを準備するものであり、ページをレンダリングしません。また、doXXX 関数呼び出しモデルはモデル メソッドのみを使用し、SQL ステートメントはありません。MVCは分離されていますが、コントローラーにもビューやモデルに関連する機能があり、かなり面倒です。
class User extends CI_Controller
{
public function register()
{
//check is logged in or not
//if not logged in , show the register page
}
public function show_register_page()
{
//generate the UI needed data , and call the view to render, and will the user will post back a valid_register function
}
public function valid_register()
{
//do all the valid logic, if success,
//do the do_register
//if fail, valid_register_fail
}
public function valid_register_fail()
{
//check is logged in or not
//show the valid register fail page
}
public function show_valid_register_fail_page()
{
//generate the UI needed data , and call the view to render
}
public function do_register()
{
//insert data in the db, the Model will be called
//if something go wrong in db, show the error page
//if everything is success, show the register success
}
public function show_db_error_page()
{
//generate the UI needed data , and call the view to render
}
public function show_register_success()
{
//generate the UI needed data , and call the view to render
}
}