Я хочу заполнить список имен в раскрывающемся списке, используя 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
Codeigniter3 form_dropdown () ошибка: неопределенная переменная ⇐ Php
Кемеровские программисты php общаются здесь
-
Anonymous
1739311728
Anonymous
Я хочу заполнить список имен в раскрывающемся списке, используя form_dropdown (...) и соответственно извлечь соответствующее имя. Хорошо, но я не могу передать второй аргумент функции form_dropdown (), по моему мнению. Я получаю ошибку «Неопределенная переменная: ветвь», я попытался сбросить значения, возвращаемые getBranch (), и она работает. ), «Форма» (где я заполняю детали для нового студента) и «индекс-преднамеренный» (сценарий jQuery для DataTable). Обратите внимание, что все представления находятся в одном каталоге /папке «Студенты», как видно в функции индекса контроллера.
Я новичок в CodeIgniter 3. < /p>
[b] класс контроллера [/b]
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);
}
[b] класс модели [/b]
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);
}
[b] view (форма, не индекс) [/b]
Branch
[b] добавить метод [/b]
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'));
}
}
[b] Основное представление [/b] только показывает, где загружаются другие страницы. Некоторые сценарии сняты, это сценарии заголовка и нижнего колонтитула.
[i][/i]
Подробнее здесь: [url]https://stackoverflow.com/questions/75733263/codeigniter3-form-dropdown-error-undefined-variable[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия