Kohana加載model php
example: 事件
model: ip
<?php defined('SYSPATH') or die('No direct script access.');
class Model_Interface extends Model {
/*
@param $event_id 事件ID;
$arr 要寫入的數據;
*/
public function do_file_write($id,$array)
{
$time = time();
$data = date("Y-m-d","$time");
$filename="$id.txt";
//$arr = array(0=>"1",1=>"2",2=>"3",3=>"4",4=>"5",5=>"6");
$d1 = implode(";", $array);
$data1 = $d1."\r\n";
//file_exists($filename);exit;
if(is_dir("interface/$data")){
echo 1;
$dir ="D:/wamp/www/php-kohana/interface/"."$data/"."$filename";
if(file_exists($dir)){
echo 2;
file_put_contents("$dir", $data1,FILE_APPEND);
}else{
echo 3;
file_put_contents("$dir", $data1,FILE_APPEND);
}
}else{
echo 4;
mkdir("interface/$data",0777);
$dir ="D:/wamp/www/php-kohana/interface/"."$data/"."$filename";
$fp=fopen("$filename", "w");
file_put_contents("$dir", $data);
fclose($fp);
}
}
}
it
controler: io
<?php defined('SYSPATH') OR die('No direct access allowed.');
class Controller_Page_Test extends Controller
{
public function action_index()
{
$event_id = "v001";
$arr = array(0=>"1",1=>"2",2=>"3",3=>"4",4=>"5",5=>"7");
$interface = new Model_Interface();
$interface->do_file_write($event_id,$arr);
}
}
event