个性化阅读
专注于IT技术分析

在CodeIgniter中传递参数

点击下载

现在, 我们将看到一个将参数从控制器传递到视图的示例。

1)下载CodeIgniter并命名。我们将其命名为params。

2)在application / controllers文件夹中创建一个文件para.php。

<?php
if(!defined('BASEPATH')) exit('No direct script access allowed'); 
class Para extends CI_Controller{
// declaring variables
var $name;
	function __construct(){
	parent::__construct();
// passing value
$this->name="CodeIgniter";
}
function tut()
{
$data['name']=$this->name; 
// define variable sent to views
$this->load->view('para_view', $data);
 }
}
?>

3)在application / views文件夹中创建一个文件para_view.php。

<!DOCTYPE html>
<html>
<head>
	<title>Passing Parameter</title>
</head>
<body>
	<h3>Hello, This is <?php echo $name ; ?> Tutorial.</h3>
</body>
</html>

4)在浏览器上使用URL运行程序

http://localhost/params/index.php/para/tut

5)以下输出将出现在屏幕上。

Codeigniter 1中的参数传递
赞(0)
未经允许不得转载:srcmini » 在CodeIgniter中传递参数

评论 抢沙发

评论前必须登录!