/** * This is the page the user hits when submitting a URL via their browser. * @return void */ public function action_submit() { $url = $this->request->post('url'); $this->page_data['code'] = FALSE; if ($url && filter_var($url, FILTER_VALIDATE_URL)) { $EzLink = new Model_EzLink(); $id = $EzLink->insertUrl($url); $this->page_data['code'] = Model_EzLink::integerToCode($id); } $this->page_data['content'] = \Sleek\View::render('pages/submit', $this->page_data, TRUE); }
/** * Program visits /api/create?url=http://www.example.com * @return void */ public function action_create() { // Disables the layout stuff $this->auto_render_layout = FALSE; // Get the ?url= parameter $url = $this->request->get('url'); if (!$url) { echo "ERROR: Empty URL"; } else { if (!filter_var($url, FILTER_VALIDATE_URL)) { echo "ERROR: Invalid URL"; } else { $EzLink = new Model_EzLink(); $id = $EzLink->insertUrl($url); // Controllers shouldn't really output directly, but it seems like a waste of a view file otherwise echo 'http://' . $this->request->server('HTTP_HOST') . '/link/' . Model_EzLink::integerToCode($id); } } }