-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewsController.php
46 lines (38 loc) · 1.24 KB
/
NewsController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
class NewsController extends AbstractController{
public function __construct(){
$this->setTitle('Aktualności');
}
public function indexAction(){
$dbNews = new Wsm_Db_News();
$list = $dbNews->getList();
$this->addToView('newsList', $list);
}
public function editAction(){
$newsDb = new Wsm_Db_News();
$this->addToView('news', $newsDb->get($this->get('id')));
}
public function saveAction(){
$news = new Wsm_News();
if($this->has('id')){
$news->setId($this->get('id'));
}
$news->setTitle($this->get('title'));
$news->setContent($this->get('content'));
$news->setSignature($this->get('signature'));
$news->setDate($this->get('date'));
$newsDb = new Wsm_Db_News();
try{
$newsDb->save($news);
$this->redirect('news/index?msg=saved');
}catch(Exception $e){
$this->redirect('news/index?msg=save_error');
}
}
public function addAction(){
$news = new Wsm_News();
$news->setDate(date("Y-m-d H:i:s"));
$news->setSignature('ZARZĄD WSM "OCHOTA"');
$this->addToView('news', $news);
}
}