Hussain
Hussain

Reputation: 5187

Yii framework on Nginx - Page doesn't load

I am trying to collaborate Nginx and Yii. I have set nginx root directory as the yii webapp as - yiic webapp /usr/share/nginx/app

In this directory I have some number of default files like yii's index.php, index-test.php along with the essential folders like protected, themes, css and images. Also I have my own files; phpinfo.php to print phpinfo() and getAttribute.php to print some columns from the mysql table history. I am able to display the phpinfo when I hit http://localhost/phpinfo.php but I can't show the output of getAttribute.php-

#getAttribute.php
<?php
public function attributeLabels() {
return array(
    Yii::t('app','model.history.sfExternalfield')=>array(
            'External Field'=>Yii::t('app','model.history.sfExternalfield'),
            'Delivery Status'=>Yii::t('app','model.history.deliveryStatus'),
    )
);
}
?>
<html>
<body><?php
print_r(attributeLabels()); 
?></body>
</html>
<?php ?>

Is there something wrong with this code?

Upvotes: 0

Views: 882

Answers (1)

bool.dev
bool.dev

Reputation: 17478

There are two things wrong with the code:

  1. As i mentioned in the comment, you can't have the public keyword without a class, so you have to remove that first.

  2. Secondly since this file is not being accessed through the index.php, but directly, it means that the framework is not yet loaded/initialized. So you don't have access to the Yii class yet. To do that you'll have to include the Yii class, somewhat like this:

    $yii='path/to/framework/yii.php';
    require_once($yii);
    // now Yii is available and you can call Yii::t();
    

Upvotes: 1

Related Questions