Codeigniter3 form_dropdown () ошибка: неопределенная переменнаяPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Codeigniter3 form_dropdown () ошибка: неопределенная переменная

Сообщение Anonymous »

Я хочу заполнить список имен в раскрывающемся списке, используя form_dropdown (...) и соответственно извлечь соответствующее имя. Хорошо, но я не могу передать второй аргумент функции form_dropdown (), по моему мнению. Я получаю ошибку «Неопределенная переменная: ветвь», я попытался сбросить значения, возвращаемые getBranch (), и она работает. ), «Форма» (где я заполняю детали для нового студента) и «индекс-преднамеренный» (сценарий jQuery для DataTable). Обратите внимание, что все представления находятся в одном каталоге /папке «Студенты», как видно в функции индекса контроллера.
Я новичок в CodeIgniter 3. < /p>
класс контроллера
public function __construct() {
parent::__construct();
is_login();
$this->load->library('form_validation');
$this->load->helper(array('form', 'url'));
$this->load->database();
$this->load->model('menu_model', 'menu');
$this->load->model('my_model', 'my');
$this->load->model('students_model', 'students');

}

public function index() {
$data['branch'] = $this->students->getBranch(); //Get the names of branches.
$data['title'] = 'Student List Home';
$data['page'] = 'students/index';
$data['datatable'] = 'students/index-datatable';
$this->load->view('back/layouts/main', $data);
}

класс модели
public function getBranch()
{
$this->db->select('id');
$this->db->select('name');
$this->db->from('branch');

$query = $this->db->get();
$result = $query->result();

$branch_id = array('-CHOOSE-');
$branch_name = array('-CHOOSE-');

for ($i = 0; $i < count($result); $i++) {
array_push($branch_id, $result[$i]->id);
array_push($branch_name, $result[$i]->name);
}
return $branch_result = array_combine($branch_id, $branch_name);
}

view (форма, не индекс)

Branch



добавить метод
public public function add()
{
if (!$_POST) {
$input = (object) $this->students->getDefaultValues();
} else {
$input = (object) $this->input->post(null, true);
}

$this->form_validation->set_rules('package_name', 'Title', 'required', [
'required' => 'Text can not be empty'
]
);
$this->form_validation->set_rules('package_fee', 'Text', 'required', [
'required' => 'Text can not be empty'
]
);
$this->form_validation->set_rules('duration', 'Text', 'required', [
'required' => 'Text can not be empty'
]
);
$this->form_validation->set_rules('category_id', 'Text', 'required', [
'required' => 'Text can not be empty'
]
);

if ($this->form_validation->run() == false) {
$data['title'] = 'Register a new Student';
$data['page'] = 'students/form';
$data['form_action'] = base_url("students/add");
$data['input'] = $input;
$this->load->view('back/layouts/main', $data);
} else {
$data = [
'title' => $this->input->post('title', true),
'firstname' => $this->input->post('firstname', true),
'lastname' => $this->input->post('lastname', true),
'othername' => $this->input->post('othername', true),
'gender' => $this->input->post('gender', true),
'dob' => $this->input->post('dob', true),
'nationality' => $this->input->post('nationality', true),
'address' => $this->input->post('address', true),
'email' => $this->input->post('email', true),
'phone_number' => $this->input->post('phone_number', true),
'education' => $this->input->post('education', true),
'occupation' => $this->input->post('occupation', true),
'nationalidtype' => $this->input->post('nationalidtype', true),
'id_number' => $this->input->post('id_number', true),
'prev_driving_exp' => $this->input->post('prev_driving_exp', true),
'photo' => $this->input->post('photo', true),
'license_type_id' => $this->input->post('license_type_id', true),
'branch_id' => $this->input->post('branch_id', true),
'group_id' => $this->input->post('group_id', true)
];

if (!empty($_FILES['photo']['name'])) {
$upload = $this->students->uploadImage();
$data['photo'] = $upload;
}

$this->students->insert($data);
$this->session->set_flashdata('success', 'Student Data added successfully');

redirect(base_url('students'));
}
}

Основное представление только показывает, где загружаются другие страницы. Некоторые сценарии сняты, это сценарии заголовка и нижнего колонтитула.
















Подробнее здесь: https://stackoverflow.com/questions/757 ... d-variable
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»