Всем привет, делаю сайт, практически в 90% контроллеров и моделях подрубаются одинаковые библиотеки и хелперы, думаю может запихать всё в автолоад, кто тестил по времени такой вариант, сильнее ли он всё грузит или нет?
И ещё, хотел узнать мнение о моём коде на примере одного метода контроллера и модели, может что делаю не так совсем и можно гораздо лучше.
Контроллер Pages, в нём метод отвечающий за страницу recruiting
public function recruiting() {
if( !file_exists(APPPATH . '/views/user/pages/recruiting.php') )
show_404();
$page_id = 4;
if($_POST) {
$request_type = 2;
$this->requests_model->add_request($request_type);
redirect('/recruiting/');
}
$data['language'] = $this->language;
$data['usd'] = $this->USD;
$data['eur'] = $this->EUR;
$data['menu_active'] = 'recruiting';
$data['meta_tags'] = $this->meta_tags_model->get_the_meta_tags($page_id);
$data['page_fields'] = $this->page_fields_model->get_the_page_fields($page_id);
$data['fields'] = $this->fields_model->get_the_fields();
$data['menu'] = $this->menu_model->get_the_menu();
$this->load->view('user/inc/top-with-meta', $data);
$this->load->view('user/inc/header', $data);
$this->load->view('user/pages/recruiting', $data);
$this->load->view('user/inc/footer', $data);
$this->data_processing->clear_session();
}
ну и модель Requests_model с методом add_request
public function add_request($request_type) {
$email_to = 'seftomsk@gmail.com';
add_an_array_to_session($_POST);
$fields = $this->fields_model->get_the_fields();
if($request_type === 2) {
$this->form_validation->set_rules('full_name', 'Full Name', 'trim|required');
$this->form_validation->set_rules('email', 'E-mail', 'trim|required');
$this->form_validation->set_rules('phone', 'phone', 'trim|required');
$this->form_validation->set_rules('address', 'Address', 'trim|required');
if( $this->form_validation->run() === FALSE || empty($_FILES['file']['name']) ) {
error( $fields[14]['value_' . $this->language] );
return false;
} else {
if( !valid_email( $this->input->post('email') ) ) {
error( $fields[16]['value_' . $this->language] );
return false;
}
$config['upload_path'] = './uploads/requests/';
$config['allowed_types'] = 'doc|pdf|jpeg|jpg|png';
$config['max_size'] = 4096;
$config['file_name'] = $this->data_processing->new_file_name( $_FILES['file']['name'] );
$this->load->library('upload', $config);
if( !$this->upload->do_upload('file') ) {
error( $fields[13]['value_' . $this->language] );
return false;
} else {
$upload_data = $this->upload->data();
$full_name = $this->data_processing->cleaning_of_empty_data( $this->input->post('full_name') );
$email = $this->data_processing->cleaning_of_empty_data( $this->input->post('email') );
$phone = $this->data_processing->cleaning_of_empty_data( $this->input->post('phone') );
$address = $this->data_processing->cleaning_of_empty_data( $this->input->post('address') );
$text = $this->data_processing->cleaning_of_empty_data( $this->input->post('message') );
$file_name = $upload_data['file_name'];
$date = time();
$subject = 'Careers';
$from_page = 'FedPay';
$message_mail = '';
$message_mail .= "Full Name: $full_name\n\r";
$message_mail .= "E-mail: $email\n\r";
$message_mail .= "Phone: $phone\n\r";
$message_mail .= "Address: $address\n\r";
$message_mail .= "Additional information and CV: $text\n\r";
$data = array(
'full_name' => $full_name,
'email' => $email,
'phone' => $phone,
'address' => $address,
'request_type_id' => $request_type
);
$query = $this->db->insert($this->name_table, $data);
if( !$query ) {
unlink('./uploads/requests/' . $file_name);
error( $fields[12]['value_' . $this->language] );
return false;
}
$request_id = $this->db->insert_id();
$data = array(
'text' => $text,
'request_id' => $request_id,
'date' => $date,
'file_name' => $file_name
);
$query = $this->db->insert('messages', $data);
if( !$query ) {
unlink('./uploads/requests/' . $file_name);
$this->delete_request($request_id);
error( $fields[12]['value_' . $this->language] );
return false;
}
if( !$this->sending_request_message($email, $from_page, $email_to, $subject, $message_mail, $file_name) ) {
unlink('./uploads/requests/' . $file_name);
$this->delete_request($request_id);
$this->delete_messages_from_request($request_id);
error( $fields[12]['value_' . $this->language] );
return false;
}
unset($_SESSION['validation_form']);
success( $fields[15]['value_' . $this->language] );
return true;
}
}
}
}