`

cakephp file components

阅读更多
1.components文件file_helper.php
<?php
class FileHelperComponent extends Object {
	
	
	//called before Controller::beforeFilter()
	function initialize(&$controller, $settings = array()) {
		// saving the controller reference for later use
		$this->controller =& $controller;
	}
	
	/**
	 * create file
	 */
	function createFile($filename,$content = null){
		$ourFileName = $filename;
		$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
		fwrite($ourFileHandle, $content);
		fclose($ourFileHandle);
	}
	
        /**
         * delete file
         */
        function delFile($filename){
                if (file_exists($filename) && is_file($filename)) {
                    unlink($filename);
                }
        }
	
	/**
	 * file content
	 */
	function getContent($filename){
		$content = file_get_contents($filename);
		return $content;
	}
	
	/**
	 * base name
	 */
	function getBaseName($filename){
		$name = basename($filename);
		return $name;
	}


	//called after Controller::render()
	function shutdown(&$controller) {
		
	}

}
?>


2.使用
  
 
    //引入
    public $components = array('FileHelper');
    
    //获得内容
    $this->FileHelper->getContent($filename);


    //获得基本文件名
    $this->FileHelper->getBaseName($filename);

    //创建文件
    $this->FileHelper->createFile($filename,$content = null);

     //删除文件
    $this->FileHelper->delFile($filename);
   
分享到:
评论

相关推荐

    PHP的框架之CakePHP-CakePHP教程

    打包下载,里面有CakePHP的框架源码,下载后可直接使用,版本是1.1的,稳定版;CakePHP的分页组件源码;CakePHP的中文及英文教程,CHM格式;CakePHP的中文打印版教程,WORD格式,下载后可直接打印,方便的;CakePHP...

    cakephp php-framework

    There are two main ways to get a fresh copy of CakePHP. You can either download an archive copy (zip/tar.gz/tar.bz2) from the main website, or check out the code from the git repository. To download ...

    cakephp 框架

    cakephp 框架 cakephp 框架 cakephp 框架 cakephp 框架 cakephp 框架

    PHP的框架之CakePHP-CakePHP教程终极教程

    打包下载,里面有CakePHP的框架源码,下载后可直接使用,版本是1.1的,稳定版;CakePHP的分页组件源码;CakePHP的中文及英文教程,CHM格式;CakePHP的中文打印版教程,WORD格式,下载后可直接打印,方便的;CakePHP...

    CakePHP 3.4 开发手册文档 CakePHP Cookbook Documentation Release 3.4

    CakePHP 3.4 开发手册文档 CakePHP Cookbook Documentation Release 3.4

    Beginning CakePHP:From Novice to Professional

    Lead you from a basic setup of CakePHP to building a couple applications that will highlight CakePHPs functionality and capabilities without delving too deeply into the PHP language, but rather ...

    cakephp分页.docx

    cakephp分页,cakephp框架的分页的方法的文档,是cakephp框架的内容。

    cakephp中acl详解

    cakephp中acl详解

    cakephp 框架书籍 英文版

    cakephp 框架书籍 英文版

    cakephp-1.2 manual

    cakephp-1.2 manual 英文版,离线版。

    cakephp-2.2.4-0

    cakephp-2.2.4-0 稳定版框架

    cakephp-1.3.21.zip

    cakephp-1.3.21.zip

    CakePHP php框架 v3.7.0 beta1.zip

    在cakephp.org站点的Sites in the wild页面可以看到当前使用CakePHP框架的网站列表。 CakePHP 是一个运用了诸如ActiveRecord、Association Data Mapping、Front Controller和MVC等著名设计模式的快速开发框架。该...

    cakephp框架源码

    cakephp框架源码cakephp框架源码cakephp框架源码cakephp框架源码cakephp框架源码cakephp框架源码cakephp框架源码cakephp框架源码cakephp框架源码

    CakePHP php框架 v3.7.8.zip

    在cakephp.org站点的Sites in the wild页面可以看到当前使用CakePHP框架的网站列表。 CakePHP 是一个运用了诸如ActiveRecord、Association Data Mapping、Front Controller和MVC等著名设计模式的快速开发框架。该...

    CakePHP php框架 v3.8.5

    在cakephp.org站点的Sites in the wild页面可以看到当前使用CakePHP框架的网站列表。CakePHP 是一个运用了诸如ActiveRecord、Association Data Mapping、Front Controller和MVC等著名设计模式的快速开发框架。该项目...

    cakephp-containable行为behaviour

    2:cakephp中虽然对模型的操作方法中并没有提供像上面提到的连贯方法 但是cake框架提供了一个containable行为类来更好的完善模型关联中遇到的上述问题 "&gt;1:thinkphp中通过框架提供的连贯操作Model &gt;join ‘other ...

    cakephp 中文手册

    cakephp 中文手册cakephp 中文手册cakephp 中文手册cakephp 中文手册

    CakePHP 3.5 开发手册文档 CakePHP Cookbook Documentation Release 3.5/共900页 PDF

    CakePHP 3.5 开发手册文档 CakePHP Cookbook Documentation Release 3.5/共900页 PDF

    Learn CakePHP(Apress,2ed,2016)

    You’ll learn about unit testing and how to implement it in CakePHP. This approach to coding leads to better code, better applications, and better programming habits. With this knowledge your ...

Global site tag (gtag.js) - Google Analytics