<?php
/*
生成的文件实例
class example
{
protected $_id;
public function getId()
{
return $this->_id;
}
public function setId($id)
{
$this->_id = $id;
}
}
*/
$fieldArr = array(
array('id', '策略id'),
array('name', '策略名称'),
array('email', '邮件'),
);
echo "<?php\n";
?>
class example{
<?php foreach ($fieldArr as $row) :?>
/**
* <?= $row[1] . "\n" ?>
*/
protected $_<?= $row[0] ?>;
<?php endforeach; ?>
<?php
foreach ($fieldArr as $row) :
$field = $row[0];
?>
public function get<?= ucfirst($field) ?>()
{
return $this->_<?= $field ?>;
}
public function set<?= ucfirst($field) ?>($<?= $field ?>)
{
$this->_<?= $field ?> = $<?= $field ?>;
}
<?php endforeach; ?>
}
<?php
$file = ob_get_contents();
file_put_contents('example.php', $file);
?>
php代码生成器
最新推荐文章于 2024-08-25 08:20:43 发布