S
S
sacred12015-02-14 08:00:34
MySQL
sacred1, 2015-02-14 08:00:34

Simple form processing?

Good day to all. I'm just starting to learn the Yii1 framework, and I'm stuck on a seemingly trivial thing. HEEEEELP!
There is the most common Index.php model (Generated in gii):

<?php

class Index extends CActiveRecord
{

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


  public function rules()
  {

    return array(
      array('title, content, create_time', 'required'),
      array('create_time', 'numerical', 'integerOnly'=>true),
      array('title', 'length', 'max'=>128),
      array('id, title, content, create_time', 'safe', 'on'=>'search'),
    );
  }


  public function relations()
  {
    return array(
    );
  }

  public function attributeLabels()
  {
    return array(
      'id' => 'ID',
      'title' => 'Title',
      'content' => 'Content',
      'create_time' => 'Create Time',
    );
  }

  public function search()
  {
    

    $criteria=new CDbCriteria;

    $criteria->compare('id',$this->id);
    $criteria->compare('title',$this->title,true);
    $criteria->compare('content',$this->content,true);
    $criteria->compare('create_time',$this->create_time);

    return new CActiveDataProvider($this, array(
      'criteria'=>$criteria,
    ));
  }

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

And the controller is IndexController.php :
<?php
class IndexController extends Controller{
    
    	public function actionIndex()
  {
            $index = new index();
            $index->title='тестовая запись';
            $index->content='содержимое записи';
            $index->save();
            //$this->render('index',array('model'=>$index));
  }
}

Do not render our data in the view, right now this is not the most important thing. And at this stage, an error will appear
. The Yii application can be created only once and swears at line 12 in the controller, namely when we create an instance of our model - $index = new Index (); .
What could be wrong? OO Did everything on the docks.
Solution
Apparently, an instance of the controller object was created, the name coincided with the model, there is no other way to explain it. Renamed the model and everything worked.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2015-02-14
@SilenceOfWinter

$index = newindex (); - $index = newIndex ();. parentheses are optional

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question