Answer the question
In order to leave comments, you need to log in
How to declare dates variable?
Good afternoon!
I added dates variable to views
<div class="content-up">
<a class="btn btn--add" href="/admin/imaps/add">Добавить материал</a>
</div>
<table class="table">
<thead class="thead">
<tr>
<th>ID</th><th>Наименование</th><th>Частота сигнала</th><th>Дата ввода</th><th>Редактировать</th><th>Удаление</th>
</tr>
</thead>
<?php foreach ($data as $item) : ?>
<tr>
<td><?= $item['Imap']['id']; ?></td>
<td><?= $item['Imap']['title']; ?></td>
<td><?= $item['Imap']['frequency']; ?></td>
<td><?= $item['Imap']['dates']; ?></td>
<td>
<a href="/admin/imaps/edit/<?=$item['Imap']['id']?>">Редактировать</a>
</td>
<td>
<?php echo $this->Form->postLink('Удалить', array('action' => 'admin_delete', $item['Imap']['id']), array('confirm' => 'Подтвердите удаление')); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
2020-08-05 09:27:54 Notice: Notice (8): Undefined index: dates in [/app/View/Imaps/admin_index.ctp, line 15]
Trace:
<?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', '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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question