前些時候在專案開發時寫了一支 API,其中大部份的方法是以 static 方式呼叫的。
最近想把這支程式放到 CodeIgniter 裡當 Library 用。第一次在 CI 呼叫 static method,用起來還挺簡潔的。
<?php
$this->load->model('user');
$user = User::get_by_email_address('qoding@example.com');
// print all of the comments by the user
echo "<h2>Comments by $user->name</h2>";
foreach ($user->comments() as $comment) {
echo "<p>$comment->body</p>";
}
?>
Leave a Reply