當前位置: 首頁>>代碼示例>>PHP>>正文


PHP file::write_file方法代碼示例

本文整理匯總了PHP中file::write_file方法的典型用法代碼示例。如果您正苦於以下問題:PHP file::write_file方法的具體用法?PHP file::write_file怎麽用?PHP file::write_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在file的用法示例。


在下文中一共展示了file::write_file方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: action_create_code

    /**
     * 生成操作節點為的代碼,要在“/Tpl/應用/”中生成“模塊-index.html、模塊-add.html、模塊-edit.html”
     *
     * @param unknown_type $node_info
     */
    private function action_create_code($action_info, $table_name, $demo_type = 'index')
    {
        //找出模塊
        $db_node = M('node');
        $module_info = $db_node->where("id='{$action_info['pid']}'")->find();
        //找出應用
        $app_info = $db_node->where("id='{$module_info['pid']}'")->find();
        $lib_file = "/Lib/Action/{$app_info['name']}/{$module_info['name']}Action.class.php";
        if (!file_exists($_SERVER['DOCUMENT_ROOT'] . $lib_file)) {
            echo '不存在此模塊';
            return false;
        }
        import("@.ORG.file");
        $file = new file();
        $content = $file->read_file($lib_file);
        //刪除代碼的最後一個字符,然後連接在一起
        $content = substr($content, 0, -1);
        $date = date('Y-m-d');
        $function = <<<EOF
    /**
     * {$action_info['title']}
     * {$action_info['remark']}
     * @author {$_SESSION['loginUserName']}
     * @date  {$date}
     */
    public function {$action_info['name']}(){
    
    }
}
EOF;
        $content = $content . $function;
        $rs = $file->write_file($lib_file, $content);
        if (!$rs) {
            return false;
        }
        //HTML文件寫入
        $table_name = $table_name ? $table_name : $module_info['name'];
        $this->create_html($app_info['name'], $module_info['name'], $action_info['name'], $demo_type, $table_name);
        return true;
    }
開發者ID:uwitec,項目名稱:p-oa,代碼行數:45,代碼來源:NodeAction.class.php

示例2: create_html

    /**
     * 創建代碼
     *
     */
    private function create_html($app_name, $module_name, $action_name, $demo_type, $table_name)
    {
        import("@.ORG.file");
        $file = new file();
        $db_field = M('field');
        $field_list = $db_field->where("table_name='{$table_name}'")->order('listorder ASC ,id ASC')->select();
        $content = $file->read_file("/Tpl/Public/Demo-{$demo_type}.html");
        switch ($demo_type) {
            case 'index':
                $textarea_height = 0;
                foreach ($field_list as $val) {
                    $name_th .= '<th><a href="?_order=' . $val['field'] . '&_sort={$sort}">' . $val['name'] . '</a><if condition="$order eq \'' . $val['field'] . '\'"><img src="__PUBLIC__/images/{$sortImg}.gif" width="9px" height="9px" alt="{$sortAlt}" /></if></th>';
                    $field_td .= '<td>{$info[' . $val['field'] . ']}</td>';
                    if ($val['formtype'] == 'textarea') {
                        //當是多行文本時要增加多2行的高度
                        $textarea_height = $textarea_height + 40;
                    }
                    if ($val['issearch']) {
                        switch ($val['formtype']) {
                            case 'select':
                            case 'radio':
                            case 'checkbox':
                                eval('$setting=' . $val['setting'] . ';');
                                $search_form .= "<select name='{$val['field']}'><option value='-1'>請選擇{$val['name']}</option>";
                                foreach ($setting as $v) {
                                    $search_form .= "<option value='{$v['value']}' <if condition=\"\$_REQUEST['{$val['field']}'] eq '{$v['value']}'\">selected=\"selected\"</if>\">{$v['name']}</option>\n";
                                }
                                $search_form .= "</select>\n";
                                break;
                            default:
                                $search_form .= "{$val['name']}:<input name='{$val['field']}' type='text' value='{\$Think.request.{$val['field']}}' />\n";
                                break;
                        }
                    }
                }
                if ($search_form) {
                    $search_form = '<div class="form-div">
					  <form name="searchForm" action="">
					    <img width="26" height="22" border="0" alt="SEARCH" src="__PUBLIC__/images/icon_search.gif">
					    ' . $search_form . '
					    <input type="submit" class="button" value=" 搜索 ">
					  </form>
					</div>';
                }
                $field_num = count($field_list);
                //計算出話框的寬和高
                $column_num = $field_num < 12 ? 2 : ($field_num % 3 == 0 ? 3 : 4);
                //可以根據字段的數量來決定有多少列
                $row_num = ceil($field_num / $column_num);
                $dialog_width = 120 * $column_num * 2;
                //因為每一個字段要占2列數據界麵
                $dialog_height = 100 + 25 * $row_num + $textarea_height;
                //設置添加、修改的對話框URL參數,隻要同一個list的action的curd操作都是和list的前綴一樣時有效
                if (strstr($action_name, 'list')) {
                    $action_pre = str_replace('list', '', $action_name);
                } else {
                    $action_pre = '';
                }
                $select = array('[¥name]', '[¥field]', '[¥search]', '[¥dialog_width]', '[¥dialog_height]', '[¥action_pre]');
                $content = str_replace($select, array($name_th, $field_td, $search_form, $dialog_width, $dialog_height, $action_pre), $content);
                $file->write_file("/Tpl/{$app_name}/{$module_name}-{$action_name}.html", $content);
            case 'export':
                foreach ($field_list as $val) {
                    $name_th .= ',' . $val['name'];
                    $field_td .= ',{$info[' . $val['field'] . ']}';
                }
                $select = array('[¥name]', '[¥field]');
                $content = str_replace($select, array($name_th, $field_td), $content);
                $file->write_file("/Tpl/{$app_name}/{$module_name}-{$action_name}.html", $content);
                break;
            case 'import':
                foreach ($field_list as $val) {
                    $field_key .= "<input name=\"field_key[{$val['name']}]\" type=\"hidden\" value=\"{$val['field']}\" />";
                }
                $content = str_replace('[¥field_key]', $field_key, $content);
                $file->write_file("/Tpl/{$app_name}/{$module_name}-{$action_name}.html", $content);
                break;
            case 'add':
                $field_num = count($field_list);
                $column_num = $field_num < 12 ? 2 : ($field_num % 3 == 0 ? 3 : 4);
                //可以根據字段的數量來決定有多少列
                $tr = 1;
                foreach ($field_list as $val) {
                    $formtype = '';
                    switch ($val['formtype']) {
                        case 'text':
                            $formtype = "<input name='{$val['field']}' type='text' class='{$val['field']}'>{$val['tips']}";
                            break;
                        case 'password':
                            $formtype = "<input name='{$val['field']}' type='password' class='{$val['field']}'>{$val['tips']}";
                            break;
                        case 'textarea':
                            $formtype = "<textarea name='{$val['field']}' class='{$val['field']}'></textarea>{$val['tips']}";
                            break;
                        case 'select':
                            $formtype = '<select name="' . $val['field'] . '" class="' . $val['field'] . '">';
//.........這裏部分代碼省略.........
開發者ID:uwitec,項目名稱:p-oa,代碼行數:101,代碼來源:ActionAction.class.php

示例3: create_app

 /**
  * 創建應用的各個文件
  */
 private function create_app($app_info)
 {
     import("@.ORG.file");
     $file = new file();
     //建立Action裏的應用文件夾
     $file->create_folder("/Lib/Action/", $app_info['name']);
     //創建Tpl下相應模塊的文件夾和默認操作HTML文件
     $file->create_folder("/Tpl/", $app_info['name']);
     //在配置文件中要自動加入這個應用
     $content = $file->read_file('/Conf/sys_app_group_list.php');
     $content = str_replace('";', ",{$app_info['name']}\";", $content);
     $file->write_file('/Conf/sys_app_group_list.php', $content, true);
     return true;
 }
開發者ID:uwitec,項目名稱:p-oa,代碼行數:17,代碼來源:AppAction.class.php

示例4: create_html

 /**
  * 創建代碼
  *
  */
 private function create_html($app_name, $module_name, $action_name, $demo_type, $table_name)
 {
     import("@.ORG.file");
     $file = new file();
     $db_field = M('field');
     $field_list = $db_field->where("table_name='{$table_name}'")->order('listorder ASC ,id ASC')->select();
     $content = $file->read_file("/Tpl/Public/Demo-{$demo_type}.html");
     switch ($demo_type) {
         case 'index':
             foreach ($field_list as $val) {
                 $name_th .= '<th>' . $val['name'] . '</th>';
                 $field_td .= '<td>{$info[' . $val['field'] . ']}</td>';
                 if ($val['issearch']) {
                     switch ($val['formtype']) {
                         case 'select':
                         case 'radio':
                         case 'checkbox':
                             eval('$setting=' . $val['setting'] . ';');
                             $search_form .= "<select name='{$val['field']}'><option value='-1'>請選擇{$val['name']}</option>";
                             foreach ($setting as $v) {
                                 $search_form .= "<option value='{$v['value']}' <if condition=\"\$_REQUEST['{$val['field']}'] eq '{$v['value']}'\">selected=\"selected\"</if>\">{$v['name']}</option>\n";
                             }
                             $search_form .= "</select>\n";
                             break;
                         default:
                             $search_form .= "{$val['name']}:<input name='{$val['field']}' type='text' value='{\$Think.request.{$val['field']}}' />\n";
                             break;
                     }
                 }
             }
             $select = array('[¥name]', '[¥field]', '[¥search]');
             $content = str_replace($select, array($name_th, $field_td, $search_form), $content);
             $file->write_file("/Tpl/{$app_name}/{$module_name}-{$action_name}.html", $content);
         case 'export':
             foreach ($field_list as $val) {
                 $name_th .= '<th>' . $val['name'] . '</th>';
                 $field_td .= '<td>{$info[' . $val['field'] . ']}</td>';
             }
             $select = array('[¥name]', '[¥field]');
             $content = str_replace($select, array($name_th, $field_td), $content);
             $file->write_file("/Tpl/{$app_name}/{$module_name}-{$action_name}.html", $content);
             break;
         case 'add':
             foreach ($field_list as $val) {
                 $formtype = '';
                 switch ($val['formtype']) {
                     case 'text':
                         $formtype = "<input name='{$val['field']}' type='text' class='{$val['field']}'>{$val['tips']}";
                         break;
                     case 'password':
                         $formtype = "<input name='{$val['field']}' type='password' class='{$val['field']}'>{$val['tips']}";
                         break;
                     case 'select':
                         $formtype = '<select name="' . $val['field'] . '" class="' . $val['field'] . '">';
                         eval('$select_list=' . $val['setting'] . ';');
                         foreach ($select_list as $v) {
                             $formtype .= '<option value="' . $v['value'] . '" >' . $v['name'] . '</option>';
                         }
                         $formtype .= '</select>' . $val['tips'];
                         break;
                     case 'checkbox':
                         eval('$checkbox_list=' . $val['setting'] . ';');
                         foreach ($checkbox_list as $v) {
                             $formtype .= '<input type="checkbox" name="' . $val['field'] . '[]" class="' . $val['field'] . '" value="' . $v['value'] . '" />' . $v['name'];
                         }
                         break;
                     case 'radio':
                         eval('$radio_list=' . $val['setting'] . ';');
                         foreach ($radio_list as $v) {
                             $formtype .= '<input type="radio" name="' . $val['field'] . '[]" class="' . $val['field'] . '" value="' . $v['value'] . '" />' . $v['name'];
                         }
                         break;
                     default:
                         $formtype = "<input name='{$val['field']}' type='text' class='{$val['field']}'>{$val['tips']}";
                         break;
                 }
                 $html .= "\t<tr><th>{$val['name']}</th><td>{$formtype}</td></tr>\n";
             }
             $content = str_replace('[¥html]', $html, $content);
             $file->write_file("/Tpl/{$app_name}/{$module_name}-{$action_name}.html", $content);
             break;
         case 'edit':
             foreach ($field_list as $val) {
                 $formtype = '';
                 switch ($val['formtype']) {
                     case 'text':
                         $formtype = "<input name='{$val['field']}' type='text' class='{$val['field']}' value='" . '{$info[' . $val['field'] . ']}' . "'>{$val['tips']}";
                         break;
                     case 'password':
                         $formtype = "<input name='{$val['field']}' type='password' class='{$val['field']}' value='" . '{$info[' . $val['field'] . ']}' . "'>{$val['tips']}";
                         break;
                     case 'select':
                         $formtype = '<select name="' . $val['field'] . '" class="' . $val['field'] . '">';
                         eval('$select_list=' . $val['setting'] . ';');
                         foreach ($select_list as $v) {
                             $formtype .= '<option value="' . $v['value'] . '" <if condition="$info[' . $val['field'] . '] eq \'' . $v['value'] . '\'">selected</if>>' . $v['name'] . '</option>';
//.........這裏部分代碼省略.........
開發者ID:uwitec,項目名稱:p-oa,代碼行數:101,代碼來源:IndexAction.class.php

示例5: create_module

 /**
  * 創建模塊
  *
  * @param unknown_type $module_info
  */
 private function create_module($module_info, $table_name = 'demo', $app_name = '')
 {
     import("@.ORG.file");
     $file = new file();
     if ($app_name == '') {
         $db_node = M('node');
         $app_name = $db_node->where("id='{$module_info['pid']}'")->getField('name');
     }
     //創建模塊的文件
     $content = $file->read_file("/Lib/Action/DemoAction.class.php");
     $content = str_replace('[應用名稱]', $module_info['title'], $content);
     $content = str_replace('[描述]', $module_info['remark'], $content);
     $content = str_replace('[demo]', $_SESSION['nickname'], $content);
     $content = str_replace('[日期]', date('Y-m-d'), $content);
     $content = str_replace('[數據表名]', $table_name, $content);
     $content = str_replace('class DemoAction extends', "class {$module_info['name']}Action extends", $content);
     $file->write_file("/Lib/Action/{$app_name}/{$module_info['name']}Action.class.php", $content);
     return $module_info;
 }
開發者ID:uwitec,項目名稱:p-oa,代碼行數:24,代碼來源:ModuleAction.class.php


注:本文中的file::write_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。