public function searchAction()
 {
     try {
         $tableName = $this->request->getPost('table');
         $field = $this->request->getPost('field');
         $search = $this->request->getPost('search');
         $modelName = Strings::tableNameToModelName($tableName);
         $results = array();
         if (class_exists($modelName)) {
             $pri = $modelName::primaryKeyName();
             $condition = '';
             if ($field) {
                 if ($search) {
                     $condition = "{$field} LIKE '%{$search}%'";
                     if (is_numeric($search)) {
                         $condition .= " or {$pri}={$search}";
                     }
                     $results = $modelName::find(array('conditions' => $condition, "limit" => 20));
                     $results = $results->toArray();
                 }
             }
             // TODO: Merge two parts
             parent::result(array('results' => $results, 'SQL' => $condition, 'key' => $pri));
         } else {
             parent::error(-2, "{$modelName} does not exists");
         }
     } catch (Exception $e) {
         parent::error(-3, "{$e}");
     }
     parent::error(-1, "{$modelName} ?");
 }
 public function previewAction()
 {
     $p = $this->request->getPost();
     $prefix = $p['prefix'];
     $tableName = $p['table_name'];
     if ($prefix) {
         $tableName = "{$prefix}_{$tableName}";
     }
     $modelName = Strings::tableNameToModelName($tableName);
     $path = ApplicationConfig::getConfig('product')['path'] . '\\www';
     $this->createModelConfigFile($path, $modelName, $p);
     $configPath = ApplicationConfig::getConfigPath('config.json');
     $cmdLine = "--prefix={$prefix} --table={$tableName} --config=\"{$configPath}\"";
     $c = Python3::run("build_mvc.py", $cmdLine);
     $targetHost = ApplicationConfig::getConfig('product')['host'];
     $testListUrl = "{$targetHost}/{$modelName}";
     parent::result(array('model' => $modelName, 'files' => json_decode($c), 'cmd_line' => $cmdLine, 'test_list_url' => $testListUrl, 'build' => $c));
 }