2016-03-08 31 views
1

我在Yii有一個網站。它工作完美。但是,當我升級MySql時,我遇到了一些錯誤。升級後未定義的索引:在php yii中的XXXXX MySql

1.)date():依靠系統的時區設置是不安全的。

但我已經通過定義時區解決了它。

2.)未定義索引:註冊。

我無法解決它。那麼,我該怎麼做?我的代碼如下:

public function actionIndex() { 
    $model = new Supplier('search'); 
    $model1 = new Registration('search'); 
    $model->unsetAttributes(); 
    $model1->unsetAttributes(); 

    if (isset($_REQUEST['Supplier'] , $_REQUEST['Registration'])) 
     $model->setAttributes($_REQUEST['Supplier']); 
     $model1->setAttributes($_REQUEST['Registration']); // here is the error. 

    $this->render('admin', array(
     'model' => $model, 
     'model1' => $model1, 
    )); 
} 

在這裏,如果我在我的網址定義$_REQUEST['Registration']那麼它會工作,但,我不能這樣做,因爲它無處不在我的網站。升級Mysql後出現錯誤。所以我該怎麼做?

感謝,

+1

你確定它只是MySQL的升級版本,而不是PHP版本,或者至少是它的php.ini版本嗎?兩者都缺少[date.timezone](http://docs.php.net/datetime.configuration#ini.date.timezone)配置和缺少的REQUEST參數,幾乎與MySQL無關。 – VolkerK

回答

1

好吧,我不知道該代碼應該做的,但第一件事,我注意到:

if (isset($_REQUEST['Supplier'] , $_REQUEST['Registration'])) 
    $model->setAttributes($_REQUEST['Supplier']); 
    $model1->setAttributes($_REQUEST['Registration']); // here is the error 

這部分缺少大括號。

if (isset($_REQUEST['Supplier'] , $_REQUEST['Registration'])){ 
    $model->setAttributes($_REQUEST['Supplier']); 
    $model1->setAttributes($_REQUEST['Registration']); // here is the error 
} 

會更有意義。否則,即使isset爲false,它也會嘗試設置註冊。

+0

我欣賞你,但我認爲錯誤是不同的,因爲當我嘗試下面的代碼,然後也出現錯誤:'<?php if($ _ REQUEST ['sub']!='expired'){?>

renderPartial('/layouts/navigation');?>
'it shows'Undefined index:sub' –

+2

same問題,$ _REQUEST ['sub']沒有設置,這裏沒有檢查。你應該檢查請求被設置的頁面 –

+0

在這種情況下,我應該先定義'$ _REQUEST ['sub']'?這將導致如此多的問題,因爲我的網站有大約一千次的時間!之前它正在工作。 –

1

你的錯誤在這裏:

if (isset($_REQUEST['Supplier'], $_REQUEST['Registration'])) 
    $model->setAttributes($_REQUEST['Supplier']); 
    $model1->setAttributes($_REQUEST['Registration']); // here is the error. 

它一樣:

if (isset($_REQUEST['Supplier'], $_REQUEST['Registration'])) { 
    $model->setAttributes($_REQUEST['Supplier']); 
} 

$model1->setAttributes($_REQUEST['Registration']); // here is the error. 

您正試圖獲得$_REQUEST['Registration']甚至沒有設置。因此,要解決這個問題,更改代碼:

if (isset($_REQUEST['Supplier'], $_REQUEST['Registration'])) { 
    $model->setAttributes($_REQUEST['Supplier']); 
    $model1->setAttributes($_REQUEST['Registration']); 
} 

這是很經常的人誰愛忽略大括號,當他們有對if塊一個語句錯誤。我強烈建議在任何情況下都使用花括號,即使在if區塊下只有一條語句。

不正確的做法:

if (true) 
    do_something(); 

正確的做法:

if (true) { 
    do_something(); 
} 

如果使用不正確的做法,你將有很多的,當你在裏面添加額外指令的情況下,如你想, if塊。但實際上你會在塊外添加指令。

+0

但是當我嘗試:'if($ _ REQUEST ['sub']!='expired'){$ this-> renderPartial('/ layouts/navigation'); }'然後錯誤是'Undefined index:sub' –

+0

@Dharmeshpatel老實說,我無法解釋爲什麼,因爲我沒有看到上下文,沒有看到你的代碼。您可能試圖獲取索引而不檢查索引是否存在。 –