Browse Source

增加 template 方法

xaboy 6 years ago
parent
commit
b531ccc59a
1 changed files with 13 additions and 8 deletions
  1. 13 8
      src/Form.php

+ 13 - 8
src/Form.php

@@ -362,12 +362,7 @@ class Form
      */
     public function formScript()
     {
-        ob_start();
-        $form = $this;
-        $DS = DIRECTORY_SEPARATOR;
-        require dirname(__FILE__) . $DS . 'Template' . $DS . 'createScript.min.php';
-        $script = ob_get_clean();
-        return $script;
+        return $this->template(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Template' . DIRECTORY_SEPARATOR . 'createScript.min.php');
     }
 
     /**
@@ -377,10 +372,20 @@ class Form
      */
     public function view()
     {
+        return $this->template(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Template' . DIRECTORY_SEPARATOR . 'form.php');
+    }
+
+    /**
+     * 自定义表单页面
+     *
+     * @param $templateDir
+     * @return false|string
+     */
+    public function template($templateDir)
+    {
         ob_start();
         $form = $this;
-        $DS = DIRECTORY_SEPARATOR;
-        require dirname(__FILE__) . $DS . 'Template' . $DS . 'form.php';
+        require $templateDir;
         $html = ob_get_clean();
         return $html;
     }