本文實例講述了Yii數(shù)據(jù)讀取與跳轉(zhuǎn)參數(shù)傳遞用法。分享給大家供大家參考,具體如下:
$toop=array('id'=>'aaaa','name'=>'bbbb','nickname'=>'ccccc','phone'=>'ddddd','status'=>'eeeeee','mytest'=>$te);
$test='hello world!';
$te="\$this->test='qweqw'";
$conn=Yii::app()->db;
$sql="select * from tbl_user";
$command=$conn->createCommand($sql);
$dataReader=$command->query();
//$rows=$dataReader->readAll();
while(($row=$dataReader->read())!==false) {
var_dump($row);
}
$this->render('index',array('toop'=>$toop,'var1'=>$test,'var2'=>$te));
$row的結(jié)果是:
array (size=4)
'id' => string '1' (length=1)
'username' => string 'test1' (length=5)
'password' => string 'pass1' (length=5)
'email' => string 'test1@example.com' (length=17)
array (size=4)
'id' => string '2' (length=1)
'username' => string 'test2' (length=5)
'password' => string 'pass2' (length=5)
'email' => string 'test2@example.com' (length=17)
array (size=4)
'id' => string '3' (length=1)
'username' => string 'test3' (length=5)
'password' => string 'pass3' (length=5)
'email' => string 'test3@example.com' (length=17)
$rows的結(jié)果:
array (size=21)
0 =>
array (size=4)
'id' => string '1' (length=1)
'username' => string 'test1' (length=5)
'password' => string 'pass1' (length=5)
'email' => string 'test1@example.com' (length=17)
1 =>
array (size=4)
'id' => string '2' (length=1)
'username' => string 'test2' (length=5)
'password' => string 'pass2' (length=5)
'email' => string 'test2@example.com' (length=17)
2 =>
array (size=4)
'id' => string '3' (length=1)
'username' => string 'test3' (length=5)
'password' => string 'pass3' (length=5)
'email' => string 'test3@example.com' (length=17)
3 =>
array (size=4)
'id' => string '4' (length=1)
'username' => string 'test4' (length=5)
'password' => string 'pass4' (length=5)
'email' => string 'test4@example.com' (length=17)
$dataReader->read() 與 $dataReader->readAll() 不能同時使用 當$dataReader->read()讀完之后$dataReader->readAll()讀取的為空,反之一樣。
通過render傳遞的參數(shù)可以這樣調(diào)用:
<?php
var_dump($toop);
var_dump($var1);
var_dump($var2);
?>
希望本文所述對大家基于Yii框架的PHP程序設(shè)計有所幫助。
2025國考·省考課程試聽報名