Sander Declerck
Sander Declerck

Reputation: 2545

PHP Yii framework just echoes AR class

I just started writing my first Yii application, but my AR class doesn't seem to work correctly.

This is my AR class:

class Activiteit extends CActiveRecord
{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return 'activiteit';
    }
}

This is my index view:

<?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name;

$activiteiten = Activiteit::model()->findAll();
?>

Somehow, this is the "html" generated:

class Activiteit extends CActiveRecord
{
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    public function tableName()
    {
        return 'activiteit';
    }
}

Index action:

public function actionIndex()
{
   // renders the view file 'protected/views/site/index.php'
   // using the default layout 'protected/views/layouts/main.php'
   $this->render('index');
}

So, why does Yii just echo my AR class?

PS: without the $activiteiten = Activiteit::model()->findAll(); line, it generates the correct html page...

Upvotes: 0

Views: 111

Answers (1)

bool.dev
bool.dev

Reputation: 17478

Check that you have stored and correctly written the class.

In common cases model files are stored in projectname/protected/models/ folder.

And the class should be something like(say Activiteit.php):

<?php // i think you missed this start tag
   class Activiteit extends CActiveRecord
   {
      // ... your code ...
   }

Use gii to auto generate code and avoid such mistakes.

Upvotes: 1

Related Questions