/**
  * Generate controller
  */
 public function createAction()
 {
     if ($this->request->isPost()) {
         $controllerName = $this->request->getPost('name', 'string');
         $directory = $this->request->getPost('directory', 'string');
         $moduleName = $this->request->getPost('module', 'string');
         $namespace = $this->request->getPost('namespace', 'string');
         $baseClass = $this->request->getPost('baseClass', 'string');
         $force = $this->request->getPost('force', 'int');
         $view = $this->request->getPost('view', 'int');
         try {
             $controllerBuilder = new Controller(array('name' => $controllerName, 'module' => $moduleName, 'directory' => $directory, 'namespace' => $namespace, 'baseClass' => $baseClass, 'force' => $force));
             $controllerFileName = $controllerBuilder->build();
             if (!empty($view)) {
                 $viewBuilder = new View(array('name' => $controllerName, 'module' => $moduleName, 'force' => $force));
                 $viewBuilder->build();
             }
             $this->flash->success('The controller "' . $controllerFileName . '" was created successfully');
             if (!empty($view)) {
                 $this->flash->success('The view for controller "' . $controllerFileName . '" was created successfully');
             }
         } catch (\Exception $e) {
             $this->flash->error($e->getMessage());
         }
     }
     $this->dispatcher->forward(array('action' => 'index'));
 }
Exemple #2
0
 /**
  * Build the controller
  *
  * @return string
  * @throws \Exception
  */
 public function build()
 {
     if (!is_dir($this->_options['directory']) || $this->_options['force'] == true) {
         if (!is_dir($this->_options['directory'])) {
             if (!@mkdir($this->_options['directory'])) {
                 throw new \Exception("Unable to create module directory!");
             }
             @chmod($this->_options['directory'], 0777);
         }
     } else {
         throw new \Exception("Module directory already exists!");
     }
     if (!is_dir($this->_options['directory'] . Tools::getControllersDir())) {
         if (!@mkdir($this->_options['directory'] . Tools::getControllersDir())) {
             throw new \Exception("Unable to create controller directory!");
         }
         @chmod($this->_options['directory'] . Tools::getControllersDir(), 0777);
     }
     $controller = new Controller(array('module' => $this->_options['name'], 'name' => 'IndexController', 'namespace' => null, 'baseClass' => current(Tools::getBaseController()), 'directory' => $this->_options['directory'] . DIRECTORY_SEPARATOR . Tools::getControllersDir(), 'force' => $this->_options['force']));
     $controller->build();
     if (!is_dir($this->_options['directory'] . Tools::getModelsDir())) {
         if (!@mkdir($this->_options['directory'] . Tools::getModelsDir())) {
             throw new \Exception("Unable to create model directory!");
         }
         @chmod($this->_options['directory'] . Tools::getModelsDir(), 0777);
     }
     if (!is_dir($this->_options['directory'] . Tools::getFormsDir())) {
         if (!@mkdir($this->_options['directory'] . Tools::getFormsDir())) {
             throw new \Exception("Unable to create form directory!");
         }
         @chmod($this->_options['directory'] . Tools::getFormsDir(), 0777);
     }
     if (!is_dir($this->_options['directory'] . Tools::getViewsDir())) {
         if (!@mkdir($this->_options['directory'] . Tools::getViewsDir())) {
             throw new \Exception("Unable to create controller directory!");
         }
         @chmod($this->_options['directory'] . Tools::getViewsDir(), 0777);
     }
     $view = new View(array('name' => 'IndexController', 'module' => $this->_options['name'], 'force' => $this->_options['force']));
     $view->build();
     if ($this->_options['routes']) {
         $this->_createRoute();
     }
     $this->_createModule();
 }