CodeIgniter

CodeIgniter学习小结–HelloWorld

如何利用codeigniter建立一个简单的helloworld,本节介绍如何建立视图和控制器。首先在application/controllers文件夹下面建立一个hello.php

<?php
// application/controllers/hello.php
class Hello extends CI_Controller {
  public function index() {
    $view_params = array (
        'title' => '欢迎使用CodeIgniter',
        'message' => 'Hello World!' 
    );
    $this->load->view ( 'helloview', $view_params );
  }
}

然后在application/views文件夹下面建立helloview.php

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<title><?php echo $title ?></title>
</head>
<body>
  <h1><?php echo $title?></h1>
  <hr>
  <p><?php echo $message?></p>
</body>
</html>

最后打开浏览器http://localhost/index.php/hello

ci_hello

类似文章