本文整理匯總了PHP中file::read_file方法的典型用法代碼示例。如果您正苦於以下問題:PHP file::read_file方法的具體用法?PHP file::read_file怎麽用?PHP file::read_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類file
的用法示例。
在下文中一共展示了file::read_file方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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'] . '">';
//.........這裏部分代碼省略.........
示例4: analysis_file
/**
* 分析出類中的說明,和操作的類
* 第一個是模型 的一些信息
* @param unknown_type $file
* @return $arr=array(
* array('level'=>2,'title'=>'在文件中是用[title][/title]包圍 的','name'=>'類名','remark'=>'在係統中是用[des][/des]包圍的'),
* array('level'=>3,'title'=>'每一個public函數前麵的注釋用[title][/title]包圍的','name'=>'函數名','remark'=>'每一個public函數前麵的注釋')
* );
*/
private function analysis_file($file)
{
import("@.ORG.file");
$obj_file = new file();
$content = $obj_file->read_file($file);
$arr = explode('Action extends', $content);
$module_str = $arr[0];
$action_str = $arr[1];
$module_arr = explode('class', $module_str);
preg_match("/(\\[title\\])[^(\\[\\/title\\])]*(\\[\\/title\\])/", $module_str, $title);
$title = str_replace('[title]', '', str_replace('[/title]', '', $title[0]));
preg_match("/(\\[des\\])[^(\\[\\/des\\])]*(\\[\\/des\\])/", $module_str, $des);
$des = str_replace('[des]', '', str_replace('[/des]', '', $des[0]));
$title = trim($title) ? trim($title) . '模塊' : trim($module_arr[1]);
$module_info = array(array('level' => 2, 'title' => $title, 'name' => trim($module_arr[1]), 'remark' => $des));
//模塊的信息
//分析操作的信息
preg_match_all("/(public function)\\s+\\w+/", $action_str, $match_action);
$delete_action = array('__construct');
foreach ($match_action[0] as $action) {
$action_name = trim(str_replace('public function', '', $action));
if (!in_array($action_name, $delete_action)) {
//排除開一些自動生成的必需的方法
$name = trim(str_replace('_before_', '', $action_name));
$title = $name;
$remark = $name;
$action_info[] = array('level' => 3, 'name' => $name, 'title' => $title, 'remark' => $remark);
}
}
return array_merge($module_info, $action_info);
}
示例5: 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;
}