/var/www/vhosts/ihelp.ro/httpdocs/src/Controller/Admin
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Controller/Admin/SponsorsController.php (3647B)
paginate($this->Sponsors);
$this->set(compact('sponsors'));
}
/**
* View method
*/
public function view($id = null)
{
$sponsor = $this->Sponsors->get($id, [
'contain' => ['SponsorsActivities']
]);
$this->set(compact('sponsor'));
}
/**
* Add method
*/
public function add()
{
$sponsor = $this->Sponsors->newEmptyEntity();
if ($this->request->is('post')) {
$data = $this->request->getData();
$image = $data['image'];
$name = $image->getClientFilename();
$image->moveTo(WWW_ROOT . 'img' . DS . $name);
$data['image'] = $name;
$sponsor = $this->Sponsors->patchEntity($sponsor, $data);
if ($this->Sponsors->save($sponsor)) {
$this->Flash->success(__('The sponsor has been saved.'));
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Sponsors', 'action' => 'index']);
}
$this->Flash->error(__('The sponsor could not be saved. Please, try again.'));
}
$this->set(compact('sponsor'));
}
/**
* Edit method
*/
public function edit($id = null)
{
if (!empty($id) && is_numeric($id)) {
$sponsor = $this->Sponsors->get($id, [
'contain' => ['SponsorsActivities'],
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$data = $this->request->getData();
$image = $data['image'];
if ($image->getError() == 0) {
$data = $this->request->getData();
$image = $data['image'];
$name = $image->getClientFilename();
$image->moveTo(WWW_ROOT . 'img' . DS . $name);
$data['image'] = $name;
} else {
unset($data['image']);
}
$sponsor = $this->Sponsors->patchEntity($sponsor, $data);
if ($this->Sponsors->save($sponsor)) {
$this->Flash->success(__('The sponsor has been saved.'));
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Sponsors', 'action' => 'index']);
}
$this->Flash->error(__('The sponsor could not be saved. Please, try again.'));
}
} else {
$this->Flash->error(__('Oops. Please, try again.'));
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Sponsors', 'action' => 'index']);
}
$this->set(compact('sponsor'));
}
/**
* Delete method
*/
public function delete($id = null)
{
if (!empty($id) && is_numeric($id)) {
$this->request->allowMethod(['post', 'delete']);
$sponsor = $this->Sponsors->get($id);
if ($this->Sponsors->delete($sponsor)) {
$this->Flash->success(__('The sponsor has been deleted.'));
} else {
$this->Flash->error(__('The sponsor could not be deleted. Please, try again.'));
}
} else {
$this->Flash->error(__('Oops. Please, try again.'));
}
return $this->redirect(['prefix' => 'Admin', 'controller' => 'Sponsors', 'action' => 'index']);
}
}