public function edit()
    {
        if (!userHasPermission('admin:blog:blog:edit')) {

            unauthorised();
        }

        // --------------------------------------------------------------------------

        $this->data['blog'] = $this->blog_model->getById($this->uri->segment(5));

        if (empty($this->data['blog'])) {

            show404();
        }

        // --------------------------------------------------------------------------

        $this->data['page']->title = 'Manage Blogs &rsaquo; Edit "' . $this->data['blog']->label . '"';

        // --------------------------------------------------------------------------

        //  Handle POST
        if ($this->input->post()) {

            $oFormValidation = Factory::service('FormValidation');
            $oFormValidation->set_rules('label', '', 'required');
            $oFormValidation->set_rules('description', '', '');
            $oFormValidation->set_message('required', lang('fv_required'));

            if ($oFormValidation->run()) {

                $aUpdateData                = array();
                $aUpdateData['label']       = $this->input->post('label');
                $aUpdateData['description'] = $this->input->post('description');

                if ($this->blog_model->update($this->uri->segment(5), $aUpdateData)) {

                    $status  = 'success';
                    $message = 'Blog was updated successfully.';
                    $this->session->set_flashdata($status, $message);
                    redirect('admin/blog/blog/index');

                } else {

                    $this->data['error']  = 'Failed to create blog. ';
                    $this->data['error'] .= $this->blog_model->lastError();
                }

            } else {

                $this->data['error'] = lang('fv_there_were_errors');
            }
        }

        // --------------------------------------------------------------------------

        //  Load views
        Helper::loadView('edit');
    }