craryprimitiveman / create-your-own-php-framework Goto Github PK
View Code? Open in Web Editor NEW构建自己的PHP框架
License: MIT License
构建自己的PHP框架
License: MIT License
那么好的文章怎么没人看了,醉了
十二章,Compiler类中
public function compile($file = null, $params = [])
{
$path = '../views/'.$file.'.sf';
extract($params);
if (!$this->isExpired($path)) {
$compiled = $this->getCompiledPath($path);
require_once $compiled;
return;
}
$fileContent = file_get_contents($path);
$result = '';
foreach (token_get_all($fileContent) as $token) {
if (is_array($token)) {
list($id, $content) = $token;
if ($id == T_INLINE_HTML) {
foreach ($this->compilers as $type) {
$content = $this->{"compile{$type}"}($content); //这个是不是改成拼接呢 $content .= $this->{"compile{$type}"}($content);
}
}
$result .= $content;
} else {
$result .= $token;
}
}
$compiled = $this->getCompiledPath($path);
file_put_contents($compiled, $result);
require_once $compiled;
}
it's great. The new tutorial have come. Express the highest respect for those who work hard. as you ...
Deprecated: Non-static method app\controllers\SiteController::Test() should not be called statically in E:\simple-work\public\index.php on line 10
test is success~!
waiting and waiting the following tutorial . thranks for your selfless contribution .
model -> delete() err~!!
$condition[$name] = isset($this->$name) ? $this->$name : null;
It's a very good introductory tutorial. I will follow you...
在第五章节中,
public static $pdo;
/**
* Get pdo instance
* @return PDO
*/
public static function getDb()
{
if (empty(static::$pdo)) {
$host = 'localhost';
$database = 'sf';
$username = 'jun';
$password = 'jun';
static::$pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password);
static::$pdo->exec("set names 'utf8'");
}
return static::$pdo;
}
这里用static变量可以保证所有继承该Model的类用的都是同一个PDO实例,getDb方法实现了单例模式。
我疑问是为什么不使用self::$pdo
呢?
我是这样理解的:
因为子类中没有复写$pdo,所以static::$pdo
使用的一直是父类的$pdo。
但self::$pdo
也是可以实现单例模式的啊,因为它始终用的也是父类中的$pdo。
请问我这样理解的对吗?
May i give a advise for the orm interface what expected for adding a method of native query str like '$Model->query(select filed1,filed2 from $table where id=? and name=?, $id, $name)' etc. It can be also using for '$Model->query(update/delete/insert...)' .
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.