diff options
Diffstat (limited to 'application/classes/controller')
-rw-r--r-- | application/classes/controller/home.php | 7 | ||||
-rw-r--r-- | application/classes/controller/polls.php | 59 |
2 files changed, 62 insertions, 4 deletions
diff --git a/application/classes/controller/home.php b/application/classes/controller/home.php index 7ec6e86..2e353a0 100644 --- a/application/classes/controller/home.php +++ b/application/classes/controller/home.php @@ -2,10 +2,9 @@ class Home_Controller extends Controller {
public function action_index(){
- foreach(ORM::factory('fairy')->with ('tree.protector','tree.flower.protector')->find_all() as $fairy) {
- echo $fairy->tree->protector->name;
-
- }
+ $view = View::get('home');
+ $view->message = 'Have fun coding!';
+ $this->response->body=$view->render();
}
}
diff --git a/application/classes/controller/polls.php b/application/classes/controller/polls.php new file mode 100644 index 0000000..c15be88 --- /dev/null +++ b/application/classes/controller/polls.php @@ -0,0 +1,59 @@ +<?php
+class Polls_Controller extends Controller {
+
+ public $view;
+ public $template;
+
+ public function before() {
+ $this->view = View::get('main');
+ $this->template=$this->request->param('action');
+ }
+ public function action_index(){
+ $this->view->polls = ORM::factory('poll')->find_all();
+ }
+
+ public function action_poll() {
+
+ if ($this->request->method == 'POST') {
+ $option_id = $this->request->post('option');
+ $option = ORM::factory('option')->where('id', $option_id)->find();
+ $option->votes += 1;
+ $option->save();
+ $this->response-> redirect('/polls/poll/'.$option->poll->id);
+ $this->execute=false;
+ return;
+ }
+
+ $id=$this->request->param('id');
+ $this->view->poll = ORM::factory('poll')->where('id', $id)->find();
+
+ }
+
+ public function action_add(){
+ if ($this->request->method == 'POST') {
+ $poll = ORM::factory('poll');
+ $poll->question = $this->request->post('question');
+ $poll->save();
+ foreach($this->request->post('options') as $text) {
+ if (empty($text))
+ continue;
+ $option = ORM::factory('option');
+ $option->text = $text;
+ $option->save();
+ $poll->add('options',$option);
+ }
+ $this->response->redirect('/polls/');
+ return;
+ }
+
+ $this->template='add';
+ }
+
+ public function after() {
+ $this->view->template=Misc::find_file('views',$this->template);
+ $this->response->body=$this->view->render();
+ }
+
+
+}
+?>
\ No newline at end of file |