本文實例講述了Yii數據讀取與跳轉參數傳遞用法。分享給大家供大家參考,具體如下:
$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的結果是:
array (size=4) 'id' => string '1' (length=1) 'username' => string 'test1' (length=5) 'password' => string 'pass1' (length=5) 'email' => string '[email protected]' (length=17) array (size=4) 'id' => string '2' (length=1) 'username' => string 'test2' (length=5) 'password' => string 'pass2' (length=5) 'email' => string '[email protected]' (length=17) array (size=4) 'id' => string '3' (length=1) 'username' => string 'test3' (length=5) 'password' => string 'pass3' (length=5) 'email' => string '[email protected]' (length=17)
$rows的結果:
array (size=21) 0 => array (size=4) 'id' => string '1' (length=1) 'username' => string 'test1' (length=5) 'password' => string 'pass1' (length=5) 'email' => string '[email protected]' (length=17) 1 => array (size=4) 'id' => string '2' (length=1) 'username' => string 'test2' (length=5) 'password' => string 'pass2' (length=5) 'email' => string '[email protected]' (length=17) 2 => array (size=4) 'id' => string '3' (length=1) 'username' => string 'test3' (length=5) 'password' => string 'pass3' (length=5) 'email' => string '[email protected]' (length=17) 3 => array (size=4) 'id' => string '4' (length=1) 'username' => string 'test4' (length=5) 'password' => string 'pass4' (length=5) 'email' => string '[email protected]' (length=17)
$dataReader->read() 與 $dataReader->readAll() 不能同時使用 當$dataReader->read()讀完之後$dataReader->readAll()讀取的為空,反之一樣。
通過render傳遞的參數可以這樣調用:
<?php var_dump($toop); var_dump($var1); var_dump($var2); ?>
更多關於Yii相關內容感興趣的讀者可查看本站專題:《Yii框架入門及常用技巧總結》、《php優秀開發框架總結》、《smarty模板入門基礎教程》、《php日期與時間用法總結》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》
希望本文所述對大家基於Yii框架的PHP程序設計有所幫助。