/** * @return Kw_Keywords */ public static function getPeer() { return parent::getPeer(self::$_className); }
/** * 功能: * 提供创建 controller and view 的功能 * * 输入: * * 输出: * * $functions * $inputForm * * @author */ function buildCandVAction() { $this->indexAction(); if ($this->in("op")) { //获得输入数据 $appPath = $this->in("AppPath"); $om_class_name = $this->in("om_class_name"); $pkg_ctrl_name = $this->in("pkg_ctrl_name"); $do = $pkg_ctrl_name; try { class_exists($om_class_name); } catch (Exception $e) { echo "Om Class : " . $om_class_name . " is not exist."; exit; } $peerObj = Pft_Om_BaseObject::getPeer($om_class_name); $desc = $peerObj->getDescription(); //$viewPath = $this->in( "ViewPath" ); //$package_name = trim( $this->in( "package_name" ), "_" ); //$table_name = $this->in( "table_name" ); //$CtrlName = $this->in( "CtrlName" ); $PkName = $desc["pk_name"]; $pk_name = $desc["pk_name"]; $pre_fix = Pft_Config::getCfg("DB_TB_PREFIX"); $table_name = $desc["table_name"]; $disp = new Pft_Dispatcher(); $ctrlArr = $disp->analyzeDoToControllerAndAction($do); $arrPackageName = explode(DIRECTORY_SEPARATOR, $ctrlArr[0]); //对变量进行格式化 //$arrPackageName = split( "_", $package_name ); $tmpArr = $arrPackageName; unset($tmpArr[1]); //去掉ctrl $PackageName = implode(array_map("ucfirst", $tmpArr)); $package_name = implode($tmpArr, "_") . "_"; $this->_tablePreFix = $pre_fix; if (trim($pre_fix) != "") { $this->_tableOmPreFix = implode(array_map("ucfirst", split("_", $pre_fix))); } $arrTableName = split("_", $table_name); $TableName = implode(array_map("ucfirst", $arrTableName)); $var_name = $table_name; $VAR_NAME = strtoupper($var_name); if (!isset($CtrlName) || trim($CtrlName) == "") { $CtrlName = ucfirst($ctrlArr[1]); } else { $CtrlName = ucfirst($CtrlName); } $ctrl_name = strtolower($CtrlName); if (trim($PkName) == "") { $PkName = $TableName . "Id"; } if (trim($pk_name) == "") { $pk_name = $table_name . "_id"; } /* 格式化好的变量应该有如下这么多个 $table_name * $TableName $var_name $VAR_NAME $package_name * $PackageName $CtrlName 可选 $ctrl_name $PkName 可选 */ //检查路径是否存在,如不存在,则进行创建 $toAppPath = $this->_checkAndMakeAppFolder($arrPackageName); $toViewPath = $this->_checkAndMakeViewFolder($arrPackageName, $ctrl_name); $editForm = ""; // editForm 是 输出变量 $detailTable = ""; // detailTable 是 输出变量 $gridCols = ""; // gridCols 是 输出变量 $fieldList = ""; // fieldList 是 输出变量 if (strlen($table_name) > 0) { $fieldNames = $desc["fields"]; $fieldList = implode(",", $fieldNames); //echo "<pre>"; foreach ($fieldNames as $key => $val) { // 为form输出准备变量 //不显示创建时间和更新时间 忽略列表已经存在于 formBuild 中了 //if( $key == "create_at" || $key == "updated_at" ) continue; $formDataArr[$val] = $val; // 给 gridCols 增加列 //$gridCols .= "\${$var_name}sGrid->addCol(Pft_I18n::trans(\"$val\"),\"$val\");\n"; $gridCols .= "\${$var_name}s_grid->addCol(Pft_I18n::trans(\"{$val}\"),\"{$val}\");\n"; } /* 这是使用phpname时的方法 $omObj = new $omClassName(); $nameMap = $omObj->getPhpNameMap(); $fieldList = implode( ",", array_flip( $nameMap ) ); //echo "<pre>"; foreach ( $nameMap as $key => $val ) { // 为form输出准备变量 $formDataArr[$key] = $key; // 给 gridCols 增加列 $gridCols .= "\${$var_name}sGrid->addCol(Pft_I18n::trans(\"$key\"),\"$key\");\n"; } */ $editForm = Pft_View_Helper_Form::buildFormForWukong($formDataArr, "", "post", true, false, array(), array($pk_name => $pk_name)); $detailTable = Pft_View_Helper_Form::buildFormForWukong($formDataArr, "", "post", false, false, array(), array($pk_name => $pk_name)); //echo $form; //echo "</pre>"; } /** * 这两行不要放到前面去 */ $table_name = $pre_fix . $table_name; $TableName = $this->_tableOmPreFix . $TableName; //这里仅仅是为了输出 $this->output = $arrNames = compact("table_name", "var_name", "VAR_NAME", "package_name", "PackageName", "CtrlName", "ctrl_name", "PkName", "editForm", "detailTable", "gridCols", "fieldList", "pk_name", "om_class_name"); //用变量替换模板中的相关变量 $info = $this->_buildPhpFile("controller.tpl.php", $toAppPath . strtolower($ctrl_name) . ".php", $arrNames); if (strlen($table_name) > 0) { //只有对数据表的操作才有 增删改查 $info .= "\n" . $this->_buildPhpFile("add.html.tpl.php", $toViewPath . "add.html.php", $arrNames); $info .= "\n" . $this->_buildPhpFile("detail.html.tpl.php", $toViewPath . "detail.html.php", $arrNames); $info .= "\n" . $this->_buildPhpFile("edit.html.tpl.php", $toViewPath . "edit.html.php", $arrNames); $info .= "\n" . $this->_buildPhpFile("list.html.tpl.php", $toViewPath . "list.html.php", $arrNames); $info .= "\n" . $this->_buildPhpFile("_editform.html.tpl.php", $toViewPath . "_editform.html.php", $arrNames); $info .= "\n" . $this->_buildPhpFile("_detailtable.html.tpl.php", $toViewPath . "_detailtable.html.php", $arrNames); } $info .= "\n<a href=\"?do={$pkg_ctrl_name}_index\">?do={$pkg_ctrl_name}_index</a>"; //输出本页再次显示的数据 $inputForm = array("AppPath" => $appPath, "pkg_ctrl_name" => $pkg_ctrl_name, "om_class_name" => $om_class_name); //$inputForm["other"] = $tpl; //$this->redirectToSelfAction( "index" ); } else { $info = ""; $inputForm = array("AppPath" => Pft_Config::getAppPath(1), "pkg_ctrl_name" => "", "om_class_name" => ""); } $this->info = $info; $this->inputForm = $inputForm; $this->inputFormDescc = array("AppPath" => "系统app路径,一般不用修改", "ViewPath" => "系统view路径,一般不用修改", "package_name" => "包名,使用小写字母+下划线的形式,如 ec , ec_sale", "pre_fix" => "表前缀名,如果前缀有下划线,最后请保留下划线,如pft_;如果没有前缀,则留空", "table_name" => "表名,不带表前缀,如 yonghu, yonhu_wanquan", "CtrlName" => "controller名称,如果有表名,此项无须填写。请使用首字母大写的形式,如 YonghuWanquan。", "pk_name" => "表的主关键字名称,如果主关键字是 表名_id 的形式则无须填写。如表名是 yonghu, 如pk是 yonghu_id,则无须填写,如pk是 yh_id,则需要填写。 ", "om_class_name" => "om对象的名称,如Yd_Order。 ", "pkg_ctrl_name" => "包含package名称的controller的名称,即do的去掉action后的内容,如ec_order。 "); }