Rumah > pembangunan bahagian belakang > tutorial php > ExtPHP主要用于通过PHP代码生成ExtJS的JavaScript代码

ExtPHP主要用于通过PHP代码生成ExtJS的JavaScript代码

WBOY
Lepaskan: 2016-07-25 09:10:56
asal
1394 orang telah melayarinya
ExtPHP是一个基于Thinkphp开发框架的ExtJS开发类库,使用此类库可以很方便的生成ExtJS的JavaScript代码。
  1. /**
  2. * PHPExtJs 基础对象
  3. * @License: ( http://www.apache.org/licenses/LICENSE-2.0 )
  4. * @Author: wb
  5. */
  6. class ExtBase {
  7. /**
  8. * ExtJS的基本目录,此参数是个路径
  9. * @var String
  10. */
  11. public $exthome = '';
  12. /**
  13. * ExtJS的语言环境配置,默认为zh_cn (中文)
  14. * @var String
  15. */
  16. public $extlang = 'zh_cn';
  17. /**
  18. * ExtJS的调试模式,默认为false
  19. * @var Boolean
  20. */
  21. public $debugmode = false;
  22. /**
  23. * ExtJS的内核模式,默认为false
  24. * @var Boolean
  25. */
  26. public $coremode = false;
  27. /**
  28. * ExtJS的环境目录的基准目录
  29. * @var String
  30. */
  31. public $extbasedir = "";
  32. /**
  33. * ExtJS的基本代码
  34. * @var String
  35. */
  36. public $extbasecode = "";
  37. /**
  38. * 页面所需要的Css文件
  39. * @var Array
  40. */
  41. public $pageCss = array();
  42. /**
  43. * 页面所需要的Js文件
  44. * @var Array
  45. */
  46. public $pageJs = array();
  47. /**
  48. * ExtJs的css文件
  49. * @var String
  50. */
  51. private $extcss = "";
  52. /**
  53. * ExtJS目录下的所有文件索引 格式为:array(文件名称=>文件路径)
  54. * @var Array
  55. */
  56. public $ExtALLFiels = array();
  57. /**
  58. * 定义ExtJS的基本运行文件 格式为:array(名称=>文件名称),这里只是定义了基本的几个
  59. * 如: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. * 根据基本参数设置Extjs的基本环境
  71. *
  72. * @param string $exthome ExtJS所在目录,相对于$basedir所指定的目录
  73. * @param boolen $extdebue 是否开启调试模式
  74. * @param boolen $extcore 是否是core模式
  75. * @param string $extlang 设置ExtJS语言
  76. * @param string $basedir $exthome目录所在的目录
  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. * 设置Extjs的基本目录
  84. *
  85. * @param String $exthome ExtJs文件所在的目录
  86. * @param String $basedir 所在目录是基于那个目录 默认为 ‘/’
  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. * 设置Extjs的基本环境
  105. *
  106. * @param string $exthome ExtJS所在目录,相对于$basedir所指定的目录
  107. * @param boolen $extdebue 是否开启调试模式
  108. * @param boolen $extcore 是否是core模式
  109. * @param string $extlang 设置ExtJS语言
  110. * @param string $basedir $exthome目录所在的目录
  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. * 设置extjs的语言
  122. *
  123. * @param String $lang 这里的语言只能是ExtJs中语言文件的文件名称中的语言部分,如:
  124. * ext-lang-zh_cn.js语言文件,只要zh_cn就行
  125. */
  126. public function setExtLang($lang='') {
  127. //TODO - 设置extjs的语言
  128. if (!empty($lang))
  129. $this->extlang = $lang;
  130. }
  131. /**
  132. * 获取对象的Styel设置串
  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 .= "extbasedir}{$cssfile}\">\n";
  145. } else {
  146. $tmpstr .= "extbasedir}{$this->ExtALLFiels[$this->ExtBaseFile['css']]}\">\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. * 获取对象的Script基本配置串
  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. * 获取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. * 获取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. * 获取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. * 设置页面的其它css文件
  243. * @param String Css文件名称及路径
  244. */
  245. public function setPageCssFile($fileName) {
  246. if (!empty($fileName)) {
  247. $this->pageCss[] = $fileName;
  248. }
  249. }
  250. /**
  251. * 设置页面的style样式
  252. * @param $cssString 样式串
  253. */
  254. public function setPageCss($cssString) {
  255. if (!empty($cssString)) {
  256. $this->pageCss[] = array("sytle" => $cssString);
  257. }
  258. }
  259. /**
  260. * 设置页面的其它js文件
  261. * @param String JS文件名称及路径
  262. */
  263. public function setPageJsFile($fileName) {
  264. if (!empty($fileName)) {
  265. $this->pageJs[] = $fileName;
  266. }
  267. }
  268. /**
  269. * 设置页面的JS代码
  270. * @param $Js 可以是ExtFunction对象也可以是js串
  271. */
  272. public function setPageJs($Js) {
  273. if (!empty($Js)) {
  274. $this->pageJs[] = array("js" => $Js);
  275. }
  276. }
  277. /**
  278. * 设置extjs的样式
  279. *
  280. * @param String $cssName css样式名称 默认为default
  281. */
  282. public function setExtCss($cssName="default") {
  283. if ($cssName != "default") {
  284. $this->extcss = "xtheme-" . $cssName . ".css";
  285. }
  286. }
  287. /**
  288. * 把$data格式化成ExtJs的对象Json串
  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. * 读取指点文件夹$floder里面的所有内容(包括文件、文件夹和子文件夹中的所有内容)
  311. *
  312. * @param String $floder 文件夹名称(目录名)可以是相对目录
  313. * @param Array POT $retarr 内容存放的数组指针
  314. */
  315. public function ReadALLFile($floder, &$retarr = array()) {
  316. //TODO - 读取所指定的文件夹$floder里面的所有内容(包括文件和文件夹,子文件夹中的内容),返回给$retarr指针
  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. * 读取所指定的文件夹$floder里面的内容(包括文件和文件夹)
  351. *
  352. * @param String $floder
  353. * @return Array
  354. */
  355. public function ReadFloder($floder) {
  356. //TODO - 读取所指定的文件夹$floder里面的内容(包括文件和文件夹)
  357. if (!is_dir($floder)) {
  358. throw new ThinkException("不能设置ExtJs的运行环境,请检查设置的目录:$floder");
  359. }
  360. $flod = array();
  361. $files = array();
  362. $dh = opendir($floder);
  363. if (!$dh) {
  364. throw new ThinkException("打开目录:" . dirname("../") . " 错误!");
  365. }
  366. while (false !== ($filename = readdir($dh))) {
  367. if ($filename != "." && $filename != "..") {
  368. if (strpos($filename, ".") $flod[] = $filename;
  369. else
  370. $files[] = $filename;
  371. }
  372. }
  373. return array($flod, $files);
  374. }
  375. /**
  376. * 设置对象的属性
  377. * @param String $key
  378. * @param Mixed $val
  379. */
  380. public function __set($key, $val) {
  381. if (property_exists($this, $key)) {
  382. if ($key == "extlang") {
  383. $this->setExtLang($val);
  384. } else {
  385. $this->$key = $val;
  386. }
  387. }
  388. }
  389. /**
  390. * 获取对象属性值
  391. * @param String $key
  392. * @return Mixed
  393. */
  394. public function __get($key) {
  395. if (empty($key))
  396. return false;
  397. if (property_exists($this, $key)) {
  398. if ($key == "extbasecode")
  399. return $this->getExtBaseCode();
  400. else
  401. return $this->$key;
  402. }
  403. return true;
  404. }
  405. /**
  406. * 将对象以String的方式返回
  407. * @return String
  408. */
  409. public function __toString() {
  410. return $this->getExtBaseCode();
  411. }
  412. }
  413. ?>
复制代码
  1. /**
  2. * PHPExtJs的对象生成类
  3. * @License: ( http://www.apache.org/licenses/LICENSE-2.0 )
  4. * @Author: wb
  5. */
  6. class ExtFunction {
  7. /**
  8. * 对象的参数集
  9. * @var Array 参数集
  10. */
  11. protected $param = array();
  12. /**
  13. * 对象代码
  14. * @var String 对象代码串
  15. */
  16. protected $code = '';
  17. /**
  18. * JS对象表示法的名称
  19. * @var String 对象名称
  20. */
  21. protected $clsname = '';
  22. /**
  23. * 根据参数$param、代码$code和$clsnames设置Ext function对象
  24. *
  25. * @param Mixed $param function的参数列表 如:"val,val1" 或者array("val","val1")
  26. * @param Mixed $code functiond的代码,可以跟对象
  27. * @param String $clsname Ext自定义对象名称
  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. * 设置对象的参数
  37. * @param String $param 参数 可以是数组
  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. * 设置对象的代码
  50. * @param Mixed $code 可以是代码串或者是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名称
  74. * @param String $clsname 对象名称
  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. '/[\f\n\r\t]*/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. ?>
复制代码
  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. * 根据$properties属性创建Ext对象
  11. *
  12. * @param String $ExtClass 对象名称 如:Ext.TabPanel、Ext.grid.GridPanel 等
  13. * @param Array $properties 对象属性数组 如:
  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='test',则产生 为 var test = new $ExtClass () {} 的代码
  23. * @param Boolen $showkeys 是否显示配置数组$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. * 设置对象的属性 即 $key = $val;
  35. *
  36. * @param String $key 属性名称 必须满足ExtJS个对象的规定
  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. * 设置属性$name的属性值为 $property
  64. *
  65. * @param String $name 属性名称
  66. * @param Mixed $property 属性值
  67. */
  68. public function setProperty($name, $property) {
  69. if (!empty($name)) {
  70. $this->state [$name] = $property;
  71. }
  72. }
  73. /**
  74. * 根据配置数组$properties设置ExtClass属性
  75. *
  76. * @param ConfigArray $properties 配置数组
  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. * 返回构建好的ExtJs对象的Js代码
  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页面对象
  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. * 根据页面模板输出extjshtml代码
  16. * 模板中可以包括{charset},{title},{extbase},{extjs},{body}
  17. *
  18. * @param String $title 页面标题
  19. * @param String $extjs extjs代码
  20. * @param String $body 页面body
  21. * @param String $charset 页面编码设置,默认为UTF-8
  22. * @param String $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. * 新建ExtJs的数据集,如果是表格数据在自动格式化为表格的Json的数据格式
  16. *
  17. * @param Array $DataArray 数据集
  18. * @param String $DataName 数据集名称
  19. * @param Blooen $isGridData 是否是表格数据
  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. * 设置ExtData对象的数据集
  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. *获取对象的Js串
  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. * 以JS的方式输出$Data的数据
  70. *
  71. * @param Array $Data 要输出的数据
  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. * 根据$config配置viewport
  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. * 根据属性值$value设置$property属性
  40. *
  41. * @param String $property 属性名称
  42. * @param Mixed $value 属性值
  43. */
  44. public function setProperty($property,$value){
  45. if(!empty($property) && !empty($value)) $this->property[$property] = $value;
  46. }
  47. /**
  48. * 添加Viewport的显示对象
  49. *
  50. * @param ExtObject $object
  51. */
  52. public function addItems($object){
  53. if(!empty($object)){
  54. $this->items[] = $object;
  55. }
  56. }
  57. /**
  58. * 初始化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. * 获取viewport的JS
  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. * 生成Extjs的窗口
  23. * @param String $name 窗口名称
  24. * @param Array $config 配置数组
  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. * 根据属性值$value设置$property属性
  68. *
  69. * @param String $property 属性名称
  70. * @param Mixed $value 属性值
  71. */
  72. public function setProperty($property, $value) {
  73. if (! empty ( $property ) && ! empty ( $value ))
  74. $this->property [$property] = $value;
  75. }
  76. /**
  77. * 添加Windows的显示对象
  78. *
  79. * @param ExtObject $object
  80. */
  81. public function addItems($object) {
  82. if (! empty ( $object )) {
  83. $this->winitems [] = $object;
  84. }
  85. }
  86. /**
  87. * 添加Windows的工具
  88. *
  89. * @param Mixed $object
  90. */
  91. public function addBbar($object) {
  92. if (! empty ( $object )) {
  93. $this->winbbar [] = $object;
  94. }
  95. }
  96. /**
  97. * 添加Windows的按钮
  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. * 获得windows对象的JS
  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. ?>
复制代码
  1. vendor("com.qldx.ext.*");
  2. class FormWin extends Form {
  3. /**
  4. * 窗体加载初始数据的对象
  5. * @var ExtObject
  6. */
  7. public $formLoad = null;
  8. /**
  9. * 窗体读取数据的对象
  10. * @var ExtObject
  11. */
  12. public $formreader = null;
  13. /**
  14. * 加载数据时传递的参数
  15. * @var Mixed
  16. */
  17. public $formLoadParam = null;
  18. /**
  19. * 窗口对象
  20. * @var ExtObject
  21. */
  22. public $windolg = null;
  23. /**
  24. * 窗体字段集
  25. * @var Array
  26. */
  27. public $fieldset = array();
  28. /**
  29. * 初始化窗体对象的代码
  30. * @var String
  31. */
  32. public $initcorde = '';
  33. /**
  34. * 窗体不含按钮 默认为false意为含有按钮
  35. * @var Bloon
  36. */
  37. public $noButton = false;
  38. /**
  39. * 构造窗体
  40. * @param String $formName 窗体名称
  41. * @param String $ModelName 窗体关联数据表模型名
  42. * @param Mixed $dataId 窗体关联数据的ID
  43. * @param Array $Properties 窗体属性数组
  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. * 设置窗体默认的初始化代码
  82. * @param Mixed $code 代码串或者ExtObject对象
  83. */
  84. public function setFormInitCode($code) {
  85. $this->initcorde->SetCode($code);
  86. }
  87. /**
  88. * 设置窗体加载事件 注意:当$obj为空时添加默认的Loader 如果要传第其它参数,必须
  89. * 先通过setFormLoaderParam方法设置加载时的其他对象
  90. * @param ExtObject $obj form的Loader对象
  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. * 设置窗体的数据加载Loader对象的属性
  124. * @param String $attrib
  125. * @param Mixed $value
  126. */
  127. public function setFormLoaderProperty($attrib, $value) {
  128. $this->formLoad->setProperty($attrib, $value);
  129. }
  130. /**
  131. * 设置额外的窗体加载对象的参数
  132. * @param String $param 参数名称
  133. * @param Mixed $value 参数值
  134. */
  135. public function setFormLoaderParam($param, $value) {
  136. $this->formLoadParam->setProperty($param, $value);
  137. }
  138. /**
  139. * 设置窗口容器的属性
  140. * @param String $attrib
  141. * @param Mixed $value
  142. */
  143. public function setWindowsProperty($attrib, $value) {
  144. $this->windolg->setProperty($attrib, $value);
  145. }
  146. /**
  147. * 设置窗体读数据标识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. * 添加窗体的默认添加按钮
  203. * @param String $name 默认为:save
  204. * @param String $title 默认为:保存
  205. * @param ExtFunction $hander 默认的事件响应对象
  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:'请稍候',
  218. waitMsg : '正在处理请求...',
  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('系统错误','服务器出现错误请稍后再试!');
  234. }
  235. });
  236. }
  237. ");
  238. }
  239. $this->addButton($name, $title);
  240. $this->setButtonAttrib($name, 'handler', $hander);
  241. }
  242. /**
  243. * 添加默认取消按钮
  244. * @param String $name
  245. * @param String $title
  246. * @param ExtFunction $hander
  247. */
  248. public function addCancelButton($name = 'cancle', $title='取消', $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. * 根据model对象名称设置FormWin的数据model
  259. *
  260. * @param String $modelName model对象名称
  261. * @param Mixed $id 要编辑到记录号
  262. */
  263. public function setDataModel($modelObject, $id) {
  264. $this->setDataSource($modelObject, $id);
  265. }
  266. /**
  267. * 根据model对象名称设置FormWin的数据model
  268. * @param String $modelName model对象名称
  269. */
  270. public function setDataModelByName($modelName) {
  271. if (!empty($modelName)) {
  272. $model = D($modelName);
  273. $this->setDataModel($model);
  274. }
  275. }
  276. /**
  277. * 本方法返回此对象的JS串
  278. * @return String 本对象的JS串
  279. */
  280. public function getJavascript() {
  281. $this->initForm();
  282. $this->setFormInt();
  283. $this->setFormReader();
  284. $this->setFormLoader();
  285. //并入窗体的数据加载对象
  286. $this->setFormInitCode("
  287. this.fp.load(" . $this->formLoad->render() . ");
  288. ");
  289. //设置窗体基本属性
  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. //创建窗口
  298. $this->windolg->setProperty(
  299. "createFormPanel",
  300. new ExtFunction(null,
  301. array("return" => $this->formbody->render())
  302. )
  303. );
  304. //添加按钮
  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('保存',this.save,this);
  314. this.addButton('取消', 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. ?>
复制代码


sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan