Example #1
0
 public function action_delete($id)
 {
     if (Session::has('id')) {
         $account = Account::find(Session::get('id'));
         // Check if admin
         if ($account->admin) {
             if ($page = Staticpage::find($id)) {
                 if ($page->id != 1) {
                     $page->delete();
                     return Redirect::to('/about');
                 } else {
                     $pages = Staticpage::all();
                     $alert = '<div class="alert alert-error" style="margin-top: 45px; margin-bottom: -45px;"><strong>Error!</strong> ' . 'You cannot delete the main About page.</div>';
                     Session::put('alert', $alert);
                     $view = View::make('about.index')->with('title', 'About')->with('pages', $pages)->with('page', $page);
                     return $view;
                 }
             } else {
                 die("Invalid Listing ID");
             }
         } else {
             // Not an admin
             $alert = '<div class="alert alert-error" style="margin-top: 45px; margin-bottom: -45px;"><strong>Error!</strong> ' . 'You must be an admin to create pages.</div>';
             Session::put('alert', $alert);
             $pages = Staticpage::all();
             $page = $pages[0];
             $view = View::make('about.index')->with('title', 'About')->with('pages', $pages)->with('page', $page);
             return $view;
         }
     } else {
         // Not logged in
         $alert = '<div class="alert alert-error" style="margin-top: 45px; margin-bottom: -45px;"><strong>Error!</strong> ' . 'You are not logged in.</div>';
         Session::put('alert', $alert);
         $pages = Staticpage::all();
         $page = $pages[0];
         $view = View::make('about.index')->with('title', 'About')->with('pages', $pages)->with('page', $page);
         return $view;
     }
 }
Example #2
0
/**
 * Here, we are connecting '/' (base path) to controller called 'Pages',
 * its action called 'display', and we pass a param to select the view file
 * to use (in this case, /app/View/Pages/home.ctp)...
 */
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**
 * ...and connect the rest of 'Pages' controller's URLs.
 */
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
Router::connect('/dashboard', array('controller' => 'users', 'action' => 'login', 'prefix' => 'admin'));
Router::parseExtensions('rss', 'xml');
//parse XML extension
Router::connect('/sitemap', array('controller' => 'sitemaps', 'action' => 'index'));
//rewrite URL
App::uses("Staticpage", "Model");
$n = new Staticpage();
$nx = $n->find("all");
foreach ($nx as $nr) {
    Router::connect('/' . $nr['Staticpage']['slug'], array('controller' => 'Staticpages', 'action' => 'view', $nr['Staticpage']['id']));
}
/**
 * Load all plugin routes. See the CakePlugin documentation on
 * how to customize the loading of plugin routes.
 */
CakePlugin::routes();
/**
 * Load the CakePHP default routes. Only remove this if you do not want to use
 * the built-in default routes.
 */
require CAKE . 'Config' . DS . 'routes.php';