// Get environment & autoloader. require __DIR__ . '/config.php'; // Create services and inject into the app. $di = new \Anax\DI\CDIFactoryDefault(); $di->set('form', '\\Mos\\HTMLForm\\CForm'); $di->set('FormController', function () use($di) { $controller = new \Anax\HTMLForm\FormController(); $controller->setDI($di); return $controller; }); $di->set('FormSmallController', function () use($di) { $controller = new \Anax\HTMLForm\FormSmallController(); $controller->setDI($di); return $controller; }); $app = new \Anax\MVC\CApplicationBasic($di); // Home route $app->router->add('', function () use($app) { $app->theme->setTitle("Testing CForm with Anax"); $app->views->add('default/page', ['title' => "Try out a form using CForm", 'content' => "This is a example showing how to use CForm with Anax MVC, you must have CForm loaded as part of Anax MVC to make this frontcontroller work.", 'links' => [['href' => $app->url->create('test1'), 'text' => "Form as a route"], ['href' => $app->url->create('form'), 'text' => "Form as a controller"], ['href' => $app->url->create('form-small'), 'text' => "Form as own class, used by a controller"]]]); }); // Test form route $app->router->add('test1', function () use($app) { $app->session(); // Will load the session service which also starts the session $form = $app->form->create([], ['name' => ['type' => 'text', 'label' => 'Name of contact person:', 'required' => true, 'validation' => ['not_empty']], 'email' => ['type' => 'text', 'required' => true, 'validation' => ['not_empty', 'email_adress']], 'phone' => ['type' => 'text', 'required' => true, 'validation' => ['not_empty', 'numeric']], 'submit' => ['type' => 'submit', 'callback' => function ($form) { $form->AddOutput("<p><i>DoSubmit(): Form was submitted. Do stuff (save to database) and return true (success) or false (failed processing form)</i></p>"); $form->AddOutput("<p><b>Name: " . $form->Value('name') . "</b></p>"); $form->AddOutput("<p><b>Email: " . $form->Value('email') . "</b></p>"); $form->AddOutput("<p><b>Phone: " . $form->Value('phone') . "</b></p>"); $form->saveInSession = true;
$controller = new Anax\Mailer\MailerController(); $controller->setDI($di); return $controller; }); $di->setShared('db', function () { $db = new \Mos\Database\CDatabaseBasic(); $db->setOptions(require ANAX_APP_PATH . 'config/config_mysql.php'); $db->connect(); return $db; }); $di->setShared('flash', function () use($di) { $flash = new Nilstr\FlashMessages\FlashMessages(); $flash->setDI($di); return $flash; }); $app = new \Anax\MVC\CApplicationBasic($di); $app->url->setUrlType(\Anax\Url\CUrl::URL_CLEAN); $app->session(); //Start Routing $app->router->add('', function () use($app) { $app->theme->setTitle("Hem"); $app->dispatcher->forward(['controller' => 'hem', 'action' => 'index']); }); $app->router->add('fragor', function () use($app) { $app->dispatcher->forward(['controller' => 'fragor', 'action' => 'index']); }); $app->router->add('taggar', function () use($app) { $app->dispatcher->forward(['controller' => 'taggar', 'action' => 'index']); }); $app->router->add('anvandare', function () use($app) { $app->dispatcher->forward(['controller' => 'anvandare', 'action' => 'index']);