ExtPHP is mainly used to generate JavaScript code for ExtJS from PHP code.

WBOY
Release: 2016-07-25 09:10:56
Original
1354 people have browsed it
ExtPHP is an ExtJS development class library based on the Thinkphp development framework. Using this kind of library can easily generate ExtJS JavaScript code.
  1. /**
  2. * PHPExtJs base object
  3. * @License: ( http://www.apache.org/licenses/LICENSE-2.0 )
  4. * @Author: wb
  5. */
  6. class ExtBase {
  7. /**
  8. * The base directory of ExtJS, this parameter is a path
  9. * @var String
  10. */
  11. public $exthome = '';
  12. /**
  13. * ExtJS locale configuration, the default is zh_cn (Chinese)
  14. * @var String
  15. */
  16. public $extlang = 'zh_cn';
  17. /**
  18. * ExtJS debugging mode, default is false
  19. * @var Boolean
  20. */
  21. public $debugmode = false;
  22. /**
  23. * Kernel mode for ExtJS, default is false
  24. * @var Boolean
  25. */
  26. public $coremode = false;
  27. /**
  28. * Base directory of ExtJS’s environment directory
  29. * @var String
  30. */
  31. public $extbasedir = "";
  32. /**
  33. *Basic code for ExtJS
  34. *@var String
  35. */
  36. public $extbasecode = "";
  37. /**
  38. * Css files required by the page
  39. * @var Array
  40. */
  41. public $pageCss = array();
  42. /**
  43. * Js files required for the page
  44. * @var Array
  45. */
  46. public $pageJs = array();
  47. /**
  48. * ExtJs css file
  49. * @var String
  50. */
  51. private $extcss = "";
  52. /**
  53. * The index of all files in the ExtJS directory is in the format: array (file name => file path)
  54. * @var Array
  55. */
  56. public $ExtALLFiels = array();
  57. /**
  58. * Define the basic running file of ExtJS. The format is: array (name => file name). Here are only the basic ones defined
  59. * Such as: base, all, css, core, debug
  60. * @var Array
  61. */
  62. public $ExtBaseFile = array(
  63. 'base' => 'ext-base.js',
  64. 'all' => 'ext-all.js',
  65. 'css' => 'ext-all.css',
  66. 'core' => 'ext-core.js',
  67. 'debug' => 'ext-all-debug.js',
  68. );
  69. /**
  70. * Set the basic environment of Extjs according to basic parameters
  71. *
  72. * @param string $exthome The directory where ExtJS is located, relative to the directory specified by $basedir
  73. * @param boolen $extdebue Whether to enable debugging mode
  74. * @param boolen $extcore Whether It is core mode
  75. * @param string $extlang Set the ExtJS language
  76. * @param string $basedir The directory where the $exthome directory is located
  77. */
  78. public function __construct($exthome = '', $basedir='', $extdebue=false, $extcore=false, $extlang='zh_cn') {
  79. //设置基本运行环境
  80. $this->setExtBase($exthome, $basedir, $extdebue, $extcore, $extlang);
  81. }
  82. /**
  83. * Set the base directory of Extjs
  84. *
  85. * @param String $exthome The directory where the ExtJs file is located
  86. * @param String $basedir The directory where the directory is located is based on that directory. The default is ‘/’
  87. * @return Boolean
  88. */
  89. public function setExtHome($exthome="", $basedir="/") {
  90. //TODO - 设置Extjs的基本目录
  91. if (!empty($basedir)) {
  92. $this->extbasedir = str_replace("/./", "/", $basedir);
  93. }
  94. if (!empty($exthome)) {
  95. $this->ReadALLFile($exthome, $this->ExtALLFiels);
  96. if (!empty($this->ReadALLFile[$this->ExtBaseFile['base']])) {
  97. throw new Exception("不正确的exthome目录($exthome)!");
  98. }
  99. $this->exthome = $exthome;
  100. }
  101. return TRUE;
  102. }
  103. /**
  104. * Set the basic environment of Extjs
  105. *
  106. * @param string $exthome The directory where ExtJS is located, relative to the directory specified by $basedir
  107. * @param boolen $extdebue Whether to enable debugging mode
  108. * @param boolen $extcore Whether it is core mode
  109. * @param string $extlang Set the ExtJS language
  110. * @param string $basedir The directory where the $exthome directory is located
  111. * @return Boolean
  112. */
  113. public function setExtBase($exthome = '', $basedir='', $extdebue=false, $extcore=false, $extlang='zh-CN') {
  114. //设置Extjs的基本环境
  115. $this->setExtHome($exthome, $basedir);
  116. $this->setExtLang($extlang);
  117. $this->debugmode = $extdebue;
  118. return TRUE;
  119. }
  120. /**
  121. * Set the language of extjs
  122. *
  123. * @param String $lang The language here can only be the language part of the file name of the language file in ExtJs, such as:
  124. * ext-lang-zh_cn.js language file, as long as zh_cn will do
  125. */
  126. public function setExtLang($lang='') {
  127. //TODO - 设置extjs的语言
  128. if (!empty($lang))
  129. $this->extlang = $lang;
  130. }
  131. /**
  132. * Get the Styel setting string of the object
  133. */
  134. public function getExtBaseStyel() {
  135. $tmpstr = '';
  136. if (is_array($this->ExtALLFiels[$this->ExtBaseFile['css']])) {
  137. $cssfile = '';
  138. foreach ($this->ExtALLFiels[$this->ExtBaseFile['css']] as $v) {
  139. if (preg_match('//docs/i', $v) == FALSE) {
  140. $cssfile = $v;
  141. break;
  142. }
  143. }
  144. $tmpstr .= "n";
  145. } else {
  146. $tmpstr .= "n";
  147. }
  148. //设置其它css
  149. if (!empty($this->pageCss)) {
  150. foreach ($this->pageCss as $f) {
  151. if (is_array($f)) {
  152. $tmpstr .= "n";
  153. } else {
  154. $tmpstr .= "n";
  155. }
  156. }
  157. }
  158. return $tmpstr;
  159. }
  160. /**
  161. * Get the basic Script configuration string of the object
  162. * @return String
  163. */
  164. public function getExtBaseScript() {
  165. $tmp = '';
  166. $tmpstr = '';
  167. if (is_array($this->ExtALLFiels[$this->ExtBaseFile['base']])) {
  168. foreach ($this->ExtALLFiels[$this->ExtBaseFile['base']] as $v) {
  169. if (preg_match('/source/i', $v) == FALSE) {
  170. $tmp = $v;
  171. break;
  172. }
  173. }
  174. if (empty($tmp))
  175. $tmp = $this->ExtALLFiels[$this->ExtBaseFile['base']][0];
  176. }else {
  177. $tmp = $this->ExtALLFiels[$this->ExtBaseFile['base']];
  178. }
  179. $tmpstr .= "n";
  180. if ($this->debugmode) {
  181. $tmpstr .= "n";
  182. } else {
  183. $tmpstr .= "n";
  184. }
  185. if ($this->coremode) {
  186. $tmpstr .= "n";
  187. }
  188. //设置语言
  189. $ExtLangJS = 'ext-lang-{lang}.js';
  190. if (!empty($this->extlang)) {
  191. $tmpfile = strtolower(str_replace("{lang}", $this->extlang, $ExtLangJS));
  192. if (isset($this->ExtALLFiels[$tmpfile])) {
  193. $tmpstr .= "n";
  194. }
  195. }
  196. //并入其它Js文件
  197. $tmpstr .= $this->getExtPageJs();
  198. return $tmpstr;
  199. }
  200. /**
  201. * Get other settings of ExtJs
  202. * @return String
  203. */
  204. public function getExtPageJs(){
  205. $tmpstr = "";
  206. //设置其它js
  207. if (!empty($this->pageJs)) {
  208. foreach ($this->pageJs as $f) {
  209. if (is_array($f)) {
  210. $tmpstr .= "n";
  211. } else {
  212. $tmpstr .= "n";
  213. }
  214. }
  215. }
  216. return $tmpstr;
  217. }
  218. /**
  219. * Get the basic page configuration string of ExtJs
  220. * @return string
  221. */
  222. public function getExtBaseJs() {
  223. //s.gif
  224. $tmpstr = '';
  225. $tmpstr .= "n";
  226. if (!empty($this->extcss) && isset($this->ExtALLFiels[$this->extcss])) {
  227. $tmpstr .= "n";
  228. }
  229. return $tmpstr;
  230. }
  231. /**
  232. * Get all configuration strings of ExtJs
  233. * @return String
  234. */
  235. public function getExtBaseCode() {
  236. $this->extbasecode .= $this->getExtBaseStyel();
  237. $this->extbasecode .= $this->getExtBaseScript();
  238. $this->extbasecode .= $this->getExtBaseJs();
  239. return $this->extbasecode;
  240. }
  241. /**
  242. * Set other css files on the page
  243. * @param String Css file name and path
  244. */
  245. public function setPageCssFile($fileName) {
  246. if (!empty($fileName)) {
  247. $this->pageCss[] = $fileName;
  248. }
  249. }
  250. /**
  251. * Set the style of the page
  252. * @param $cssString style string
  253. */
  254. public function setPageCss($cssString) {
  255. if (!empty($cssString)) {
  256. $this->pageCss[] = array("sytle" => $cssString);
  257. }
  258. }
  259. /**
  260. * Set other js files on the page
  261. * @param String JS file name and path
  262. */
  263. public function setPageJsFile($fileName) {
  264. if (!empty($fileName)) {
  265. $this->pageJs[] = $fileName;
  266. }
  267. }
  268. /**
  269. * Set the JS code of the page
  270. * @param $Js can be an ExtFunction object or a js string
  271. */
  272. public function setPageJs($Js) {
  273. if (!empty($Js)) {
  274. $this->pageJs[] = array("js" => $Js);
  275. }
  276. }
  277. /**
  278. * Set the style of extjs
  279. *
  280. * @param String $cssName css style name The default is default
  281. */
  282. public function setExtCss($cssName="default") {
  283. if ($cssName != "default") {
  284. $this->extcss = "xtheme-" . $cssName . ".css";
  285. }
  286. }
  287. /**
  288. * Format $data into ExtJs object Json string
  289. *
  290. * @param Array $data
  291. * @return String
  292. */
  293. public function ExtJsonFormat($data) {
  294. $i = 0;
  295. $retstr .= "{";
  296. foreach ($data as $k => $v) {
  297. if ($i > 0)
  298. $retstr .= ",";
  299. if (is_string($v) && !is_numeric($v) && strtolower($v) != "true" && strtolower($v) != "false") {
  300. $retstr .= "$k:'$v'";
  301. }
  302. else
  303. $retstr .= "$k:$v";
  304. $i++;
  305. }
  306. $retstr .= "}";
  307. return $retstr;
  308. }
  309. /**
  310. * Read all contents in the pointed folder $floder (including all contents in files, folders and subfolders)
  311. *
  312. * @param String $floder The folder name (directory name) can be a relative directory
  313. * @ param Array POT $retarr Array pointer where the content is stored
  314. */
  315. public function ReadALLFile($floder, &$retarr = array()) {
  316. //TODO - Read all contents in the specified folder $floder (including files and files folder, the contents of subfolders), returned to the $retarr pointer
  317. $tpath = '';
  318. $app_path = str_replace('\', '/', getcwd()) . "/";
  319. //echo "APP_PATH:".$app_path." BASE:".$this->extbasedir."
    n";
  320. if (strpos($this->extbasedir, $app_path) == FALSE) {
  321. $ tpath = $app_path . "/" . $floder;
  322. } else {
  323. $tpath = $this->extbasedir . "/" . $floder;
  324. }
  325. $tpath = preg_replace(array('/{2,} /', '//{2,}/'), '/', $tpath);
  326. $tmparr = $this->ReadFloder($tpath);
  327. if ($tmparr != FALSE && is_array($ tmparr)) {
  328. foreach ($tmparr[0] as $v) {
  329. $this->ReadALLFile($floder . '/' . $v, $retarr);
  330. }
  331. if (!empty($tmparr[ 1])) {
  332. foreach ($tmparr[1] as $v) {
  333. $k = strtolower($v);
  334. if (isset($retarr[$k])) {
  335. $tmpstr = preg_replace('/ /{2,}/', "/", $floder . '/' . $v);
  336. if (is_array($retarr[$k])) {
  337. $retarr[$k][] = $tmpstr;
  338. } else {
  339. $retarr[$k] = array($retarr[$k], $tmpstr);
  340. }
  341. } else {
  342. $retarr[$k] = preg_replace('//{2,}/' , "/", $floder . '/' . $v);
  343. }
  344. }
  345. }
  346. }
  347. array_change_key_case($retarr);
  348. }
  349. /**
  350. * Read the contents (including files and folders) of the specified folder $floder
  351. *
  352. * @param String $floder
  353. * @return Array
  354. */
  355. public function ReadFloder($floder ) {
  356. //TODO - Read the contents of the specified folder $floder (including files and folders)
  357. if (!is_dir($floder)) {
  358. throw new ThinkException("Cannot set the operating environment of ExtJs, Please check the set directory: $floder");
  359. }
  360. $flod = array();
  361. $files = array();
  362. $dh = opendir($floder);
  363. if (!$dh) {
  364. throw new ThinkException("Open directory:" . dirname("../") . " Error! ");
  365. }
  366. while (false !== ($filename = readdir($dh))) {
  367. if ($filename != "." && $filename != "..") {
  368. if (strpos( $filename, ".") <= 0)
  369. $flod[] = $filename;
  370. else
  371. $files[] = $filename;
  372. }
  373. }
  374. return array($flod, $files);
  375. }
  376. /**
  377. * Set the properties of the object
  378. * @param String $key
  379. * @param Mixed $val
  380. */
  381. public function __set($key, $val) {
  382. if (property_exists($this, $key)) {
  383. if ($key == "extlang") {
  384. $this-> ;setExtLang($val);
  385. } else {
  386. $this->$key = $val;
  387. }
  388. }
  389. }
  390. /**
  391. * Get the object attribute value
  392. * @param String $key
  393. * @return Mixed
  394. */
  395. public function __get($key) {
  396. if ( empty($key))
  397. return false;
  398. if (property_exists($this, $key)) {
  399. if ($key == "extbasecode")
  400. return $this->getExtBaseCode();
  401. else
  402. return $ this->$key;
  403. }
  404. return true;
  405. }
  406. /**
  407. * Return the object as String
  408. * @return String
  409. */
  410. public function __toString() {
  411. return $this->getExtBaseCode();
  412. }
  413. }
  414. ?> ;
Copy code
  1. /**
  2. * PHPExtJs object generation class
  3. * @License: ( http://www.apache.org/licenses/LICENSE-2.0 )
  4. * @Author: wb
  5. */
  6. class ExtFunction {
  7. /**
  8. * Object parameter set
  9. * @var Array parameter set
  10. */
  11. protected $param = array();
  12. /**
  13. * Object code
  14. * @var String Object code string
  15. */
  16. protected $code = '';
  17. /**
  18. * The name of JS object notation
  19. * @var String Object name
  20. */
  21. protected $clsname = '';
  22. /**
  23. * Set the Ext function object according to the parameter $param, code $code and $clsnames
  24. *
  25. * @param Mixed $param function parameter list such as: "val, val1" or array("val", "val1")
  26. * @param Mixed $code functiond code, you can follow the object
  27. * @param String $clsname Ext custom object name
  28. *
  29. */
  30. public function __construct($param = null, $code = null, $clsname = null) {
  31. $this->SetParam($param);
  32. $this->SetCode($code);
  33. $this->clsname = $clsname;
  34. }
  35. /**
  36. * Set the parameters of the object
  37. * @param String $param parameter can be an array
  38. */
  39. public function SetParam($param) {
  40. if (is_array($param)) {
  41. $this->param = array_merge($this->param, $param);
  42. } elseif (is_string($param) && preg_match("/,/", $param)) {
  43. $this->param = array_merge($this->param, split(',', $param));
  44. } else {
  45. $this->param [$param] = $param;
  46. }
  47. }
  48. /**
  49. * Code to set the object
  50. * @param Mixed $code can be a code string or other object of PHPExtJS
  51. */
  52. public function SetCode($code) {
  53. if (!empty($this->code) && is_object($this->code) && method_exists($this->code, 'render')) {
  54. $this->code = $this->code->render();
  55. }
  56. if (is_object($code) && method_exists($code, 'render')) {
  57. $this->code .= $code->render();
  58. } else if (is_string($code)) {
  59. $this->code .= $code;
  60. }
  61. if (is_array($code)) {
  62. foreach ($code as $key => $val) {
  63. if ($key === "return") {
  64. //echo "KEY:$key
    n";
  65. $this->code .= "return ";
  66. }
  67. $this->SetCode($val);
  68. $this->code .= ";";
  69. }
  70. }
  71. }
  72. /**
  73. * @param String $name DOM name
  74. * @param String $clsname Object name
  75. */
  76. public function render($name = '', $clsname = "") {
  77. $str = '';
  78. if (!empty($name)) {
  79. $str .= "var $name = function ";
  80. } else {
  81. $str .= "function ";
  82. }
  83. if (!empty($clsname))
  84. $this->clsname = $clsname;
  85. if (!empty($this->clsname)) {
  86. $str .= " " . $this->clsname . " ";
  87. $this->param = array();
  88. }
  89. $str .= "(" . implode(',', $this->param) . ")";
  90. if (!empty($this->code)) {
  91. $str .= "{";
  92. if (is_object($this->code) && method_exists($this->code, "render")) {
  93. $str .= $this->code->render();
  94. } elseif (is_string($this->code)) {
  95. $str .= $this->code;
  96. }
  97. $str .= "}";
  98. }
  99. if (!empty($name))
  100. $str .= ";";
  101. //去除注释行
  102. $search = array(
  103. '/(//.*)|(/*.**/)/i', //去掉注释
  104. '/[fnrt]*/i', //去掉回车符
  105. '/{(s)*/i',
  106. '/}(s)*}/i',
  107. '/}(s)*/i',
  108. //'/}(s)*if/i',
  109. '/(s)*}/',
  110. '/;(s)*/',
  111. '/,(s)*/i'
  112. );
  113. $replace = array(
  114. '',
  115. '',
  116. '{',
  117. '}}',
  118. '}',
  119. //'}if',
  120. '}',
  121. ';',
  122. ','
  123. );
  124. $str = preg_replace($search, $replace, $str);
  125. return $str;
  126. }
  127. public function __toString() {
  128. return $this->render();
  129. }
  130. }
  131. ?>
Copy code
  1. require_once 'ExtData.class.php';
  2. class ExtObject {
  3. protected static $indent = '';
  4. public $state = Array();
  5. public $showkeys = true;
  6. public $extClass = '';
  7. public $rendername = '';
  8. public $extend = '';
  9. /**
  10. * Create an Ext object based on the $properties property
  11. *
  12. * @param String $ExtClass Object name such as: Ext.TabPanel, Ext.grid.GridPanel, etc.
  13. * @param Array $properties Object property array such as:
  14. * Array('labelWidth ' => 150,
  15. * 'url' => 'part.submit.php',
  16. * 'frame' => true,
  17. * 'bodyStyle' => 'padding: 5px 5px 0',
  18. * 'width' => 500,
  19. * 'defaults' => new ExtObject(null, Array('width' => 290)),
  20. * 'defaultType' => 'textfield'
  21. * )
  22. * @ param String $name var name. For example: $name='test', the code generated is var test = new $ExtClass () {}
  23. * @param Boolen $showkeys Whether to display the label of the configuration array $properties
  24. */
  25. public function __construct($ExtClass = null, $properties = null, $name = null, $showkeys = true) {
  26. $this->extClass = $ExtClass;
  27. if (is_array($properties)) {
  28. $this->state = $properties;
  29. }
  30. $this->showkeys = $showkeys;
  31. $this->rendername = $name;
  32. }
  33. /**
  34. * Set the attributes of the object, that is, $key = $val;
  35. *
  36. * @param String $key attribute name must meet the requirements of ExtJS objects
  37. * @param Anly_type $val
  38. */
  39. public function __set($key, $val) {
  40. if ($key == 'indent') {
  41. $this->indent = $val;
  42. } else {
  43. $this->state [$key] = $val;
  44. }
  45. }
  46. public function __get($key) {
  47. if (isset($this->state[$key]))
  48. return $this->state [$key];
  49. }
  50. public function __isset($key) {
  51. return isset($this->state [$key]);
  52. }
  53. public function del($key) {
  54. $this->__unset($key);
  55. }
  56. public function __unset($key) {
  57. unset($this->state [$key]);
  58. }
  59. public function __toString() {
  60. return $this->render();
  61. }
  62. /**
  63. * Set the attribute value of attribute $name to $property
  64. *
  65. * @param String $name attribute name
  66. * @param Mixed $property attribute value
  67. */
  68. public function setProperty($name, $property) {
  69. if (!empty($name)) {
  70. $this->state [$name] = $property;
  71. }
  72. }
  73. /**
  74. * Set the ExtClass property according to the configuration array $properties
  75. *
  76. * @param ConfigArray $properties configuration array
  77. */
  78. public function setProperties($properties) {
  79. $this->state = array_merge($this->state, $properties);
  80. }
  81. public function setExtendsClass($ExtClass) {
  82. $this->extend = $ExtClass;
  83. }
  84. public function JSRender($items, $showkeys = true, $isparam = false) {
  85. //self::$indent .= ' ';
  86. $str = '';
  87. $total = count($items);
  88. $cnt = 1;
  89. if ($isparam && $total == 2 && is_object($items [0]) && is_array($items [1])) {
  90. $str .= "{{$this->JSRender($items[0])}},";
  91. $str .= "[{$this->JSRender($items[1])}]";
  92. } else {
  93. foreach ($items as $element => $value) {
  94. if ($showkeys) {
  95. if (is_numeric($showkeys)) {
  96. $str .= self::$indent . "'$element':";
  97. } else {
  98. if (!is_numeric($element))
  99. $str .= self::$indent . "$element: ";
  100. }
  101. }
  102. if (is_string($value)) {
  103. $str .= "'$value'";
  104. } else if (is_bool($value)) {
  105. $str .= ( $value) ? "true" : "false";
  106. } else if (is_object($value)) {
  107. if (method_exists($value, 'render')) {
  108. $str .= $value->render();
  109. }
  110. } else if (is_array($value)) {
  111. if (count($value) == 1 && is_string($value [0])) {
  112. $str .= $value [0];
  113. }else {
  114. $str .= "[";
  115. $str .= $this->JSRender($value, false);
  116. $str .= self::$indent . "]";
  117. }
  118. } else if (is_numeric($value)) {
  119. $str .= $value;
  120. } else if ($value == '') {
  121. $str .= "''";
  122. } else {
  123. $str .= $value;
  124. }
  125. if ($cnt != $total) {
  126. $str .= ",";
  127. }
  128. $cnt++;
  129. }
  130. }
  131. self::$indent = substr(self::$indent, 0, - 2);
  132. return $str;
  133. }
  134. /**
  135. * Return the Js code of the constructed ExtJs object
  136. *
  137. * @param String $name
  138. * @return String
  139. */
  140. public function render($name = null) {
  141. $str = '';
  142. if (!empty($name))
  143. $this->rendername = $name;
  144. if (
  145. preg_match('/.alert/', $this->extClass) || preg_match('/.prompt/', $this->extClass)
  146. || preg_match('/.show/', $this->extClass) || preg_match('/.confirm/', $this->extClass)
  147. || preg_match('/.progress/', $this->extClass) || preg_match('/.wait/', $this->extClass)
  148. || preg_match('/.updateProgress/', $this->extClass)
  149. || preg_match('/.updateText/', $this->extClass)
  150. ) {
  151. if (!empty($this->rendername))
  152. $str = self::$indent . "var $this->rendername = $this->extClass(";
  153. else
  154. $str = self::$indent . "$this->extClass (";
  155. $str .= $this->JSRender($this->state, FALSE);
  156. $str .= ");";
  157. } elseif (
  158. preg_match('/.ColumnModel/', $this->extClass) || preg_match('/.Record.create/', $this->extClass)
  159. ) {
  160. if (!empty($this->rendername))
  161. $str = self::$indent . "var $this->rendername = new $this->extClass([";
  162. else
  163. $str = self::$indent . "new $this->extClass ([";
  164. $str .= $this->JSRender($this->state, TRUE);
  165. $str .= "])";
  166. if ($this->rendername) {
  167. $str .= ";";
  168. }
  169. } elseif (
  170. preg_match('/.JsonReader/', $this->extClass) || preg_match('/.ArrayReader/', $this->extClass)
  171. ) {
  172. if (!empty($this->rendername))
  173. $str = self::$indent . "var $this->rendername = new $this->extClass(";
  174. else
  175. $str = self::$indent . "new $this->extClass (";
  176. if (!empty($this->state['fields'])) {
  177. $str .= "{totalProperty:'" . $this->state['totalProperty'] . "', ";
  178. $str .= "root:'" . $this->state['root'] . "'},";
  179. $str .= "[" . $this->JSRender($this->state['fields'], TRUE) . "]";
  180. } else {
  181. $str .= $this->JSRender($this->state, TRUE);
  182. }
  183. $str .= ")";
  184. if ($this->rendername) {
  185. $str .= ";";
  186. }
  187. } elseif ($this->extend) { //如果是扩展对象
  188. $str = self::$indent . $this->extClass . " = Ext.extend( $this->extend ,{";
  189. $str .= $this->JSRender($this->state, TRUE);
  190. $str .= "});";
  191. } else {
  192. if ($this->rendername) {
  193. if ($this->extClass) {
  194. $str = self::$indent . "var $this->rendername = new $this->extClass({";
  195. } else {
  196. $str = self::$indent . "var $this->rendername = {";
  197. }
  198. } elseif ($this->extClass) {
  199. echo self::$indent;
  200. $str = self::$indent . "new $this->extClass({";
  201. } else {
  202. $str = self::$indent . "{";
  203. }
  204. $str .= $this->JSRender($this->state, $this->showkeys);
  205. $str .= self::$indent . "}";
  206. if ($this->extClass) {
  207. $str .= ")";
  208. }
  209. if ($this->rendername) {
  210. $str .= ";";
  211. }
  212. }
  213. return $str;
  214. }
  215. }
  216. ?>
复制代码
  1. /**
  2. * PHPExtJs ExtJs page object
  3. * @License: ( http://www.apache.org/licenses/LICENSE-2.0 )
  4. * @Author: wb
  5. */
  6. class ExtPage {
  7. public $extjs = '';
  8. public $extbase = '';
  9. public $body = '';
  10. public $bodyPapm = '';
  11. public $title = '';
  12. public $charset = '';
  13. public $template = "";
  14. /**
  15. * Output extjshtml code according to the page template
  16. * The template can include {charset}, {title}, {extbase}, {extjs}, {body}
  17. *
  18. * @param String $title Page title
  19. * @param String $ extjs extjs code
  20. * @param String $body page body
  21. * @param String $charset page encoding setting, the default is UTF-8
  22. * @param String $template page template
  23. */
  24. public function __construct($title='', $extjs='', $extbase='', $body='', $charset='utf-8', $template='') {
  25. $this->title = $title;
  26. $this->extjs = $extjs;
  27. $this->extbase = $extbase;
  28. $this->body = $body;
  29. $this->charset = $charset;
  30. if(!empty($template)) $this->template = $template;
  31. else $this->template = "
  32. {title}
  33. {extbase}
  34. {body}
  35. ";
  36. }
  37. public function render() {
  38. if(!empty($this->template)){
  39. $search = array("{charset}","{title}","{extbase}","{extjs}","{body}","{bodyPapm}");
  40. $replace = array($this->charset,$this->title,$this->extbase,$this->extjs,$this->body,$this->bodyPapm);
  41. $this->template = str_replace($search,$replace,$this->template);
  42. echo $this->template;
  43. }else{
  44. throw new Exception("页面模板为空,请先设置页面模板!");
  45. }
  46. }
  47. public function __set($key, $val) {
  48. switch($key) {
  49. case 'extjs':
  50. $this->extjs = $val;
  51. break;
  52. case 'body':
  53. $this->body = $val;
  54. break;
  55. case 'bodyPapm':
  56. $this->bodyPapm = $val;
  57. break;
  58. case 'charset':
  59. $this->body = $val;
  60. break;
  61. case 'template':
  62. $this->template = $val;
  63. break;
  64. case 'extbase':
  65. $this->extbase = $val;
  66. break;
  67. default:
  68. throw new Exception("非法的ExtPage属性 ExtPage::$key");
  69. }
  70. }
  71. public function __get($key) {
  72. switch($key) {
  73. case 'extjs':
  74. return $this->extjs;
  75. case 'body':
  76. return $this->body;
  77. case 'bodyPapm':
  78. return $this->bodyPapm;
  79. case 'charset':
  80. return $this->charset;
  81. case 'template':
  82. return $this->template;
  83. default:
  84. throw new Exception("非法的ExtPage属性 ExtPage::$key");
  85. }
  86. }
  87. }
复制代码
  1. /**
  2. * +----------------------------------------------------------------------
  3. * | PHPExtJs
  4. * +----------------------------------------------------------------------
  5. * | @License: ( http://www.apache.org/licenses/LICENSE-2.0 )
  6. * +----------------------------------------------------------------------
  7. * | @Author: wb
  8. * +----------------------------------------------------------------------
  9. */
  10. class ExtData extends ExtBase {
  11. public $Data = array ();
  12. public $DataName = '';
  13. public $isGridData = false;
  14. /**
  15. * Create a new ExtJs data set. If it is tabular data, it will be automatically formatted into the Json data format of the table
  16. *
  17. * @param Array $DataArray Data set
  18. * @param String $DataName Data set name
  19. * @param Blooen $ isGridData is table data
  20. */
  21. public function __construct($DataArray, $DataName = '', $isGridData = false) {
  22. $this->setDataArray ( $DataArray );
  23. if (! empty ( $DataName )) {
  24. $this->DataName = $DataName;
  25. }
  26. if (is_bool ( $isGridData )) {
  27. $this->isGridData = $isGridData;
  28. }
  29. }
  30. /**
  31. * Set the data set of the ExtData object
  32. *
  33. * @param Array $DataArray
  34. */
  35. public function setDataArray($DataArray) {
  36. if (! empty ( $DataArray ) && is_array ( $DataArray )) {
  37. $this->Data = $DataArray;
  38. }
  39. }
  40. /**
  41. *Get the Js string of the object
  42. * @return string
  43. */
  44. public function getJavascript() {
  45. $str = '';
  46. if (! empty ( $this->DataName )) {
  47. $str .= "var $this->DataName = ";
  48. }
  49. if ($this->isGridData) {
  50. $j = 0;
  51. $count = count ( $this->Data );
  52. $str .= "{totalProperty:$count,root:[";
  53. foreach ( $this->Data as $value ) {
  54. if($j>0) $str .= ",";
  55. $str .= "[".$this->JSRender ( $value )."]";
  56. $j ++;
  57. }
  58. $str .= "]}";
  59. } else {
  60. $str .= "[".$this->JSRender ( $this->Data )."]";
  61. //$str .= $this->JSRender ( $this->Data );
  62. }
  63. if (! empty ( $this->DataName )) {
  64. $str .= ";";
  65. }
  66. return $str;
  67. }
  68. /**
  69. * Output the data of $Data in JS way
  70. *
  71. * @param Array $Data The data to be output
  72. */
  73. public function JSRender($Data = Array()) {
  74. $str = "";
  75. foreach ( $Data as $element => $value ) {
  76. if(!empty($str)) $str .= ",";
  77. /*if (!is_numeric($element)) {
  78. $str .= "'$element':";
  79. }*/
  80. if (is_string ( $value )) {
  81. $str .= "'$value'";
  82. } else if (is_bool ( $value )) {
  83. $str .= ($value) ? "true" : "false";
  84. } else if (is_array ( $value )) {
  85. if (count ( $value ) == 1 && is_string ( $value [0] )) {
  86. $str .= $value [0];
  87. } else {
  88. $str .= "[";
  89. $str .= $this->JSRender ( $value, false );
  90. $str .= "]";
  91. }
  92. } else {
  93. if(empty($value)){
  94. $str .= "''";
  95. }else{
  96. $str .= $value;
  97. }
  98. }
  99. }
  100. return $str;
  101. }
  102. public function render() {
  103. return $this->getJavascript ();
  104. }
  105. public function show() {
  106. echo $this->getJavascript ();
  107. }
  108. public function __toString() {
  109. return $this->getJavascript ();
  110. }
  111. }
  112. ?>
复制代码
  1. /**
  2. * +----------------------------------------------------------------------
  3. * | PHPExtJs
  4. * +----------------------------------------------------------------------
  5. * | @License: ( http://www.apache.org/licenses/LICENSE-2.0 )
  6. * +----------------------------------------------------------------------
  7. * | @Author: wb
  8. * +----------------------------------------------------------------------
  9. */
  10. include_once "ExtBase.class.php";
  11. include_once "ExtObject.class.php";
  12. include_once "ExtFunction.class.php";
  13. include_once "ExtPage.class.php";
  14. class viewport extends ExtBase{
  15. private $vpbody = null;
  16. public $property = array();
  17. public $items = array();
  18. /**
  19. * Configure viewport according to $config
  20. */
  21. public function __construct($config=array()) {
  22. if(!empty($config) && is_array($config)){
  23. foreach ($config as $k => $v){
  24. if($k == 'items') continue;
  25. $this->setProperty($k,$v);
  26. }
  27. if( !empty($config['items'])){
  28. if( is_array($config['items']) ){
  29. foreach ($config['items'] as $v){
  30. $this->addItems($v);
  31. }
  32. }else{
  33. $this->addItems($v);
  34. }
  35. }
  36. }
  37. }
  38. /**
  39. * Set the $property attribute according to the property value $value
  40. *
  41. * @param String $property property name
  42. * @param Mixed $value property value
  43. */
  44. public function setProperty($property,$value){
  45. if(!empty($property) && !empty($value)) $this->property[$property] = $value;
  46. }
  47. /**
  48. * Add the display object of Viewport
  49. *
  50. * @param ExtObject $object
  51. */
  52. public function addItems($object){
  53. if(!empty($object)){
  54. $this->items[] = $object;
  55. }
  56. }
  57. /**
  58. * Initialize viewport
  59. */
  60. private function init(){
  61. $obj = new ExtObject("Ext.Viewport",array());
  62. $obj->setProperties($this->property);
  63. $obj->setProperty("items",$this->items);
  64. $this->vpbody = $obj;
  65. }
  66. /**
  67. * Get the JS of viewport
  68. *
  69. * @return String
  70. */
  71. public function getJavascript(){
  72. $this->init();
  73. return $this->vpbody->render("vport");
  74. }
  75. /**
  76. *
  77. */
  78. public function render(){
  79. $js = $this->getJavascript ();
  80. $default = isset ( $_COOKIE ['exttheme'] ) ? $_COOKIE ['exttheme'] : $_SESSION ['SYS_THEM'];
  81. if (! empty ( $default ))
  82. $this->setExtCss ( $default ); //设置EXTJS的显示样式
  83. //建立extjs的页面并设置页面的基本ext执行环境
  84. $page = new ExtPage ( );
  85. $page->extbase = $this->getExtBaseCode (); //设置extBase
  86. $page->extjs .= "Ext.onReady(function(){";
  87. $page->extjs .= $js;
  88. $page->extjs .= "});";
  89. //$page->body = "
    ";
  90. $page->render ();
  91. }
  92. public function show(){
  93. $this->render();
  94. }
  95. public function __toString(){
  96. return $this->getJavascript();
  97. }
  98. }
  99. ?>
复制代码
  1. /**
  2. * +----------------------------------------------------------------------
  3. * | PHPExtJs
  4. * +----------------------------------------------------------------------
  5. * | @License: ( http://www.apache.org/licenses/LICENSE-2.0 )
  6. * +----------------------------------------------------------------------
  7. * | @Author: wb
  8. * +----------------------------------------------------------------------
  9. */
  10. include_once "ExtBase.class.php";
  11. include_once "ExtObject.class.php";
  12. include_once "ExtFunction.class.php";
  13. include_once "ExtPage.class.php";
  14. class Window extends ExtBase {
  15. private $winname = '';
  16. private $winbody = null;
  17. private $winitems = null;
  18. private $winbutton = null;
  19. private $winbbar = null;
  20. private $property = array ();
  21. /**
  22. * Generate Extjs window
  23. * @param String $name window name
  24. * @param Array $config configuration array
  25. */
  26. public function __construct($name,$config) {
  27. //parent::__construct ();
  28. if(!empty($name)){
  29. $this->winname = $name;
  30. }
  31. if (! empty ( $config ) && is_array ( $config )) {
  32. foreach ( $config as $k => $v ) {
  33. if ($k == 'items' || $k == 'bbar' || $k == 'buttons')
  34. continue;
  35. $this->setProperty ( $k, $v );
  36. }
  37. if (! empty ( $config ['items'] )) {
  38. if (is_array ( $config ['items'] )) {
  39. foreach ( $config ['items'] as $v ) {
  40. $this->addItems ( $v );
  41. }
  42. } else {
  43. $this->addItems ( $v );
  44. }
  45. }
  46. if (! empty ( $config ['bbar'] )) {
  47. if (is_array ( $config ['bbar'] )) {
  48. foreach ( $config ['bbar'] as $v ) {
  49. $this->addBbar ( $v );
  50. }
  51. } else {
  52. $this->addBbar ( $v );
  53. }
  54. }
  55. if (! empty ( $config ['buttons'] )) {
  56. if (is_array ( $config ['buttons'] )) {
  57. foreach ( $config ['buttons'] as $v ) {
  58. $this->addBbar ( $v );
  59. }
  60. } else {
  61. $this->addBbar ( $v );
  62. }
  63. }
  64. }
  65. }
  66. /**
  67. * Set the $property attribute according to the property value $value
  68. *
  69. * @param String $property property name
  70. * @param Mixed $value property value
  71. */
  72. public function setProperty($property, $value) {
  73. if (! empty ( $property ) && ! empty ( $value ))
  74. $this->property [$property] = $value;
  75. }
  76. /**
  77. * Add Windows display object
  78. *
  79. * @param ExtObject $object
  80. */
  81. public function addItems($object) {
  82. if (! empty ( $object )) {
  83. $this->winitems [] = $object;
  84. }
  85. }
  86. /**
  87. * Add Windows tools
  88. *
  89. * @param Mixed $object
  90. */
  91. public function addBbar($object) {
  92. if (! empty ( $object )) {
  93. $this->winbbar [] = $object;
  94. }
  95. }
  96. /**
  97. * Add Windows button
  98. *
  99. * @param Mixed $object
  100. */
  101. public function addButton($object) {
  102. if (! empty ( $object )) {
  103. $this->winbutton [] = $object;
  104. }
  105. }
  106. private function init() {
  107. $obj = new ExtObject ( "Ext.Window", array () );
  108. $obj->setProperties ( $this->property );
  109. if (! empty ( $this->winbbar ))
  110. $obj->setProperty ( "bbar", $this->winbbar );
  111. if (! empty ( $this->winitems ))
  112. $obj->setProperty ( "items", $this->winitems );
  113. if (! empty ( $this->winbutton ))
  114. $obj->setProperty ( "buttons", $this->winbutton );
  115. $this->winbody = $obj;
  116. }
  117. /**
  118. * Get the JS of windows object
  119. *
  120. * @param String $winName
  121. */
  122. public function getJavascript() {
  123. $this->init ();
  124. if (! empty ( $this->winname ))
  125. return $this->winbody->render ( $this->winname ) . "{$this->winname}.show();";
  126. else
  127. return $this->winbody->render ();
  128. }
  129. public function render($winName = '') {
  130. $js = $this->getJavascript ( $winName );
  131. //建立extjs的页面并设置页面的基本ext执行环境
  132. $page = new ExtPage ();
  133. $page->extbase = $this->getExtBaseCode (); //设置extBase
  134. $page->extjs .= "Ext.onReady(function(){";
  135. $page->extjs .= $js;
  136. $page->extjs .= "});";
  137. $page->render ();
  138. }
  139. public function show($winName = 'win1') {
  140. $this->render ( $winName );
  141. }
  142. public function __toString() {
  143. return $this->getJavascript ();
  144. }
  145. }
  146. ?>
Copy code
  1. vendor("com.qldx.ext.*");
  2. class FormWin extends Form {
  3. /**
  4. * Object for loading initial data in the form
  5. * @var ExtObject
  6. */
  7. public $formLoad = null;
  8. /**
  9. * The object from which the form reads data
  10. * @var ExtObject
  11. */
  12. public $formreader = null;
  13. /**
  14. * Parameters passed when loading data
  15. * @var Mixed
  16. */
  17. public $formLoadParam = null;
  18. /**
  19. * Window Object
  20. * @var ExtObject
  21. */
  22. public $windolg = null;
  23. /**
  24. * Form field set
  25. * @var Array
  26. */
  27. public $fieldset = array();
  28. /**
  29. * Code to initialize the form object
  30. * @var String
  31. */
  32. public $initcorde = '';
  33. /**
  34. * The form does not contain buttons. The default is false, which means it contains buttons.
  35. * @var Bloon
  36. */
  37. public $noButton = false;
  38. /**
  39. * Construct the form
  40. * @param String $formName form name
  41. * @param String $ModelName form associated data table model name
  42. * @param Mixed $dataId form associated data ID
  43. * @param Array $Properties window Body attribute array
  44. */
  45. public function __construct($formName = '', $ModelName = "", $dataId = "", $Properties = array()) {
  46. parent::__construct($formName, $ModelName, $dataId, $Properties);
  47. $this->formbody->setProperty("labelWidth", 80);
  48. $this->formbody->setProperty("defaults", array("{xtype:'textfield',anchor:'100%'}"));
  49. $this->windolg = new ExtObject("FormWin",
  50. array(
  51. 'id' => $this->formName,
  52. 'name' => $this->formName,
  53. 'dataID' => $this->dataId,
  54. 'title' => $this->formbody->title,
  55. 'collapsible' => true,
  56. 'maximizable' => true,
  57. 'layout' => 'fit',
  58. 'plain' => true,
  59. 'bodyStyle' => 'padding:5px;',
  60. 'buttonAlign' => 'center',
  61. "msk" => array("new Ext.LoadMask(Ext.getBody(), {msg : '正加载数据,请稍等...'})"),
  62. "createFormPanel" => null,
  63. "initComponent" => null
  64. )
  65. );
  66. $this->initcorde = new ExtFunction(NULL, "
  67. this.keys={
  68. key: Ext.EventObject.ENTER,
  69. fn: this.save,
  70. scope: this
  71. };
  72. FormWin.superclass.initComponent.call(this);
  73. this.fp=this.createFormPanel();
  74. this.add(this.fp);
  75. if(!this.dataID && this.loadParam.id){
  76. this.dataID = this.loadParam.id
  77. }
  78. ");
  79. }
  80. /**
  81. * Set the default initialization code of the form
  82. * @param Mixed $code code string or ExtObject object
  83. */
  84. public function setFormInitCode($code) {
  85. $this->initcorde->SetCode($code);
  86. }
  87. /**
  88. * Set the form loading event. Note: Add the default Loader when $obj is empty. If you want to pass other parameters, you must
  89. * First set other objects during loading through the setFormLoaderParam method
  90. * @param ExtObject $obj form's Loader object
  91. */
  92. public function setFormLoader($obj = null) {
  93. $tobj = null;
  94. $param = null;
  95. if ($this->dataId) {
  96. $param = new ExtObject(null, array('id' => $this->dataId));
  97. } else {
  98. $param = new ExtObject(null, array('id' => array('this.dataID')));
  99. }
  100. if (!empty($obj) && is_object($obj)) {
  101. if (!isset($obj->param) || empty($obj->param)) {
  102. $this->setProperty("loadParam", $obj->param);
  103. $this->del('param');
  104. } else { //如果加载的对象不含param则并入预先设置的loadParam
  105. $this->setProperty("loadParam", $param);
  106. }
  107. $obj->param = array("this.loadParam");
  108. $tobj = $obj;
  109. }else {
  110. $this->setProperty("loadParam", $param);
  111. $tobj = new ExtObject(null, array(
  112. "url" => __URL__ . "/getFormWinData",
  113. "params" => array('this.loadParam'),
  114. "success" => new ExtFunction(Null, "
  115. this.msk.hide();
  116. "),
  117. "scope" => array('this')
  118. ));
  119. }
  120. $this->formLoad = $tobj;
  121. }
  122. /**
  123. * Set the properties of the form's data loading Loader object
  124. * @param String $attrib
  125. * @param Mixed $value
  126. */
  127. public function setFormLoaderProperty($attrib, $value) {
  128. $this->formLoad->setProperty($attrib, $value);
  129. }
  130. /**
  131. * Set additional parameters of the form loading object
  132. * @param String $param parameter name
  133. * @param Mixed $value parameter value
  134. */
  135. public function setFormLoaderParam($param, $value) {
  136. $this->formLoadParam->setProperty($param, $value);
  137. }
  138. /**
  139. * Set the attributes of the window container
  140. * @param String $attrib
  141. * @param Mixed $value
  142. */
  143. public function setWindowsProperty($attrib, $value) {
  144. $this->windolg->setProperty($attrib, $value);
  145. }
  146. /**
  147. * Set the form reader data identifier form reader
  148. */
  149. private function setFormReader() {
  150. $this->formreader = new ExtObject(
  151. 'Ext.data.JsonReader',
  152. array(
  153. new ExtObject(
  154. null,
  155. array("root" => "data")
  156. ),
  157. $this->fieldset
  158. )
  159. );
  160. }
  161. private function setFormInt() {
  162. $twidth = 0;
  163. $tmpwidth = 16;
  164. $tmpheight = 40;
  165. //form窗体的读取数据的标志 字段名称列表
  166. foreach ($this->formFields as $n => $f) {
  167. $this->fieldset[] = new ExtObject(null, array('name' => $n, 'mapping' => $n));
  168. }
  169. //并且计算窗体的高度
  170. if (empty($this->windolg->height)) {
  171. foreach ($this->formFields as $n => $f) {
  172. if (isset($f->height) && $f->height > 0) {
  173. $tmpheight += $f->height;
  174. } else {
  175. $tmpheight += 32;
  176. }
  177. if (isset($f->width) && $f->width > $tmpwidth) {
  178. $twidth = $f->width;
  179. }
  180. }
  181. } else {
  182. $tmpheight = $this->windolg->height;
  183. $twidth = $this->windolg->width;
  184. }
  185. if (empty($tmpheight)) {
  186. $tmpheight = 200;
  187. } elseif ($tmpheight > 750) {
  188. $tmpheight = 750;
  189. }
  190. if (empty($twidth)) {
  191. $tmpwidth += $twidth;
  192. }
  193. if (empty($tmpwidth) || $tmpwidth == 16) {
  194. $tmpwidth = 340;
  195. }
  196. $this->windolg->setProperty("width", $tmpwidth);
  197. $this->windolg->setProperty("height", $tmpheight);
  198. $this->windolg->setProperty("minWidth", $tmpwidth);
  199. $this->windolg->setProperty("minHeight", $tmpheight);
  200. }
  201. /**
  202. * Add the default add button of the form
  203. * @param String $name Default is: save
  204. * @param String $title Default is: save
  205. * @param ExtFunction $hander Default event response object
  206. */
  207. public function addSaveButton($name = 'save', $title='保存', $hander=null) {
  208. if (empty($hander)) {
  209. $hander = new ExtFunction(null, "
  210. if(this.fp.form.isValid()){
  211. var turl = '" . __URL__ . "/saveFormWinData';
  212. if(this.dataID){
  213. turl += '/id/'+ this.dataID;
  214. }
  215. var fw = this;
  216. this.fp.form.submit({
  217. waitTitle: 'Please wait',
  218. waitMsg : 'Processing request...',
  219. url : turl,
  220. params: this.loadParam,
  221. success : function(form, action){
  222. fw.close();
  223. if(form.rGrid){
  224. if(form.rGrid.root){
  225. form.rGrid.getLoader().load(form.rGrid.root );
  226. }else{
  227. form.rGrid.getLoader().load();
  228. }
  229. }
  230. },
  231. failure : function() {
  232. fw.close;
  233. Ext.Msg.alert('System Error', 'An error occurred on the server, please try again later! ');
  234. }
  235. });
  236. }
  237. ");
  238. }
  239. $this->addButton($name, $title);
  240. $this->setButtonAttrib( $name, 'handler', $hander);
  241. }
  242. /**
  243. * Add default cancel button
  244. * @param String $name
  245. * @param String $title
  246. * @param ExtFunction $hander
  247. */
  248. public function addCancelButton($name = 'cancle', $title='Cancel', $hander=null) {
  249. if (empty($hander)) {
  250. $hander = new ExtFunction(null, "
  251. this.close();
  252. ");
  253. }
  254. $this->addButton($name, $title);
  255. $this- >setButtonAttrib($name, 'handler', $hander);
  256. }
  257. /**
  258. * Set FormWin's data model according to the model object name
  259. *
  260. * @param String $modelName model object name
  261. * @param Mixed $id to be edited to the record number
  262. */
  263. public function setDataModel($modelObject, $id) {
  264. $this->setDataSource($modelObject, $id);
  265. }
  266. /**
  267. * Set the FormWin data model according to the model object name
  268. * @param String $modelName model object name
  269. */
  270. public function setDataModelByName($modelName) {
  271. if (!empty($modelName)) {
  272. $model = D($modelName);
  273. $this- >setDataModel($model);
  274. }
  275. }
  276. /**
  277. * This method returns the JS string of this object
  278. * @return String The JS string of this object
  279. */
  280. public function getJavascript() {
  281. $this->initForm();
  282. $this->setFormInt();
  283. $this->setFormReader();
  284. $this->setFormLoader();
  285. //Data loading object incorporated into the form
  286. $this->setFormInitCode("
  287. this.fp.load(" . $this ->formLoad->render() . ");
  288. ");
  289. //Set the basic properties of the form
  290. if (empty($this->formbody->baseCls)) {
  291. $this-> formbody->setproperty('baseCls', 'x-plain');
  292. }
  293. if (empty($this->formbody->reader)) {
  294. $this->formbody->setProperty(" reader", $this->formreader);
  295. }
  296. $this->formbody->setProperty("items", $this->getElementArray());
  297. //Create window
  298. $this-> windolg->setProperty(
  299. "createFormPanel",
  300. new ExtFunction(null,
  301. array("return" => $this->formbody->render())
  302. )
  303. );
  304. //Add button
  305. if (!$this->noButton) {
  306. if (!empty($this->formButtons) && is_array($this->formButtons)) {
  307. foreach ($this->formButtons as $k => ; $v) {
  308. $this->initcorde->SetCode("this.addButton('" . $v->text . "',this." . $k . ",this);");
  309. $this->windolg->setProperty($k, $v->handler);
  310. }
  311. } else {
  312. $this->initcorde->SetCode("
  313. this.addButton('Save' ,this.save,this);
  314. this.addButton('Cancel', function(){this.close();},this);
  315. ");
  316. }
  317. }
  318. $this->windolg-> setProperty("initComponent", $this->initcorde);
  319. $this->windolg->setExtendsClass("Ext.Window");
  320. return $this->formExtendJs . $this->windolg-> ;render();
  321. }
  322. }
  323. ?>
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template