私は他の何ものでもスタイルや組織に関して質問があります。私はしばしば、複数のajax呼び出しを必要とする単一のページ(コントローラ)を持っていることがよくあります。AJAXコントローラとカレントコントローラは別々ですか?
class Management extends MY_Controller
{
public function __construct()
{
parent::__construct();
$this->protect->protect();
if ($this->uri->segment(2, 0) !== 0 && !$this->input->is_ajax_request()) {
exit('No direct script access allowed');
}
}
public function index()
{
$this->load->model('management_model');
$data['row_config'] = $this->management_model->getConfigRows();
$data['row_users'] = $this->management_model->getUsers();
$data['roles'] = $this->management_model->getRoles();
$this->tpl->head();
$this->load->view('management/scripts');
$this->tpl->body();
if ($this->messages->hasMessages()) {
$this->output->append_output($this->messages->display());
}
$this->load->view('management/manage', $data);
$this->load->view('management/current_users', $data);
$this->load->view('management/modals', $data);
$this->tpl->footer();
}
public function get_user_details()
{
$user = new \Auth\ASUser($_POST['userId']);
echo json_encode($user->getAll());
}
public function delete_user()
{
$user = new \Auth\ASUser($_POST['userId']);
$user->deleteUser(true);
}
インデックスは、私が実際に適切なビューをレンダリングする必要がある唯一のページがあるので、残り:それは、次の私はやる以上のコントローラを意味しますので、むしろちょうどAJAXのための別のコントローラを作成するよりは、呼び出し、私はちょうどインデックス以外のものが存在するかどうかを確認するためにURIセグメントをチェックし、そのajax要求があるかどうかを確認します。
この悪い習慣ですか? AJAX呼び出しとView Controllerを分離する必要がありますか?