function add() { if ($this->request->is_post()) { $item = new WatchlistItem($_POST); $item->utente = $_COOKIE['username']; $item->save(); $this->redirect_to(array('action' => 'index')); } else { if (!empty($_GET['id'])) { $this->stock = new Stock(); $this->stock->find_by_id($_GET['id']); $this->render(array('action' => 'add_by_isin')); } else { $stock_factory = new Stock(); $stocks = $stock_factory->find_all(array('where_clause' => '`attivo` = 1', 'order_by' => '`title` ASC')); $this->stocks = array('-1' => 'Scegli...'); foreach ($stocks as $stock) { $this->stocks[$stock->isin] = $stock->title; } } } }