Answer the question
In order to leave comments, you need to log in
How is the frequency variable written to the database?
Good afternoon!
Help me understand how the variable "frequency" gets into the database. The site is written in CakePHP
Here is the editing template:
<div class="content-up">
<span class="content-up__heading">Редактирование материала</span>
</div>
<div class="add-part">
<?php
echo $this->Form->create('Imap', array('type' => 'file'));
?>
<div class="edit_bot">
<div class="bot_r">
<?php
echo $this->Form->input('region_id', array('label' => 'Область:', 'class' => 'region_list'));?>
<select id="districts" name="data[Imap][district_id]">
<option value="0">Выберите район</option>
<?php foreach($districts as $key => $value): ?>
<option value="<?=$key?>" <?=($key == $data['Imap']['district_id']) ? 'selected' : ''?>><?=$value?></option>
<?php endforeach ?>
</select>
<select class="towns" name="data[Imap][town_id]">
<option value="0">Выберите населенный пункт</option>
<?php foreach($towns as $key => $value): ?>
<option value="<?=$key?>" <?=($key == $data['Imap']['town_id']) ? 'selected' : ''?>><?=$value?></option>
<?php endforeach ?>
</select>
<?php
echo $this->Form->input('title', array('label' => 'Наименование:'));
echo $this->Form->input('dates', array('label' => 'Дата ввода:'));
echo $this->Form->input('frequency', array('label' => 'Частота сигнала:'));
echo $this->Form->input('latitude', array('label' => 'Широта:'));
echo $this->Form->input('longitude', array('label' => 'Долгота:'));
echo $this->Form->input('diameter', array('label' => 'Диаметр:'));
echo $this->Form->end('Редактировать');
?>
</div>
</div>
<script type="text/javascript">
//CKEDITOR.replace( 'editor' );
</script>
</div>
<?php
class ImapsController extends AppController{
public function beforeFilter(){
parent::beforeFilter();
}
// public $uses = array('Imap', 'Region');
public function admin_index(){
$data = $this->Imap->find('all');
$this->set(compact('data'));
}
public function admin_add(){
if($this->request->is('post')){
$this->Imap->create();
$data = $this->request->data['Imap'];
if($this->Imap->save($data)){
$this->Session->setFlash('Сохранено', 'default', array(), 'good');
return $this->redirect($this->referer());
}else{
$this->Session->setFlash('Ошибка', 'default', array(), 'bad');
}
}
$this->Imap->Region->locale = 'ru';
$regions = $this->Imap->Region->find('list');
$this->set(compact('title_for_layout', 'regions'));
}
public function admin_edit($id){
if(is_null($id) || !(int)$id || !$this->Imap->exists($id)){
throw new NotFoundException('Такой страницы нет...');
}
$data = $this->Imap->findById($id);
if(!$id){
throw new NotFoundException('Такой страницы нет...');
}
if($this->request->is(array('post', 'put'))){
$this->Imap->id = $id;
$data1 = $this->request->data['Imap'];
$data1['id'] = $id;
if($this->Imap->save($data1)){
$this->Session->setFlash('Сохранено', 'default', array(), 'good');
return $this->redirect($this->referer());
}else{
$this->Session->setFlash('Ошибка', 'default', array(), 'bad');
}
}
//Заполняем данные в форме
if($this->request->is('post')){
$this->request->data = $data1;
$data = $data1;
}else{
$data = $this->request->data = $this->Imap->read(null, $id);
}
$this->Imap->Region->locale = 'ru';
$this->Imap->District->locale = 'ru';
$this->Imap->Town->locale = 'ru';
$regions = $this->Imap->Region->find('list');
$districts = $this->Imap->District->find('list');
$towns = $this->Imap->Town->find('list');
$this->set(compact('id', 'data', 'regions','districts', 'dates', 'towns'));
}
public function admin_delete($id){
if (!$this->Imap->exists($id)) {
throw new NotFounddException('Такой статьи нет');
}
if($this->Imap->delete($id)){
$this->Session->setFlash('Удалено', 'default', array(), 'good');
}else{
$this->Session->setFlash('Ошибка', 'default', array(), 'bad');
}
return $this->redirect($this->referer());
}
}
Answer the question
In order to leave comments, you need to log in
$this->Form->create('Imap', array('type' => 'file'));
//...
$data = $this->request->data['Imap'];
accordingly, $data will contain data from all form fields
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question