in my fist aplication in yiii how i crate a model whit no database

in this Creating First Yii Application guide some guy named ivolucien comment and put some helpfull information, i started with this whoopass tutorial “Where to Start with Yii” and creating my first aplication in yii for a helloword with editable message, but i can’t create a model without a database, but in this tutorial says that we can but doesn’t says how.


So let’s build our model and controller, if you’re confused on how to do this, type help within the shell to get the specifics. For the controller, add the additional actions of show and edit. Once completed, you can see where all the files were created and you can even use the test link to view your web application template in your web server. I used Message as my ID for everything but feel free to put String or HelloWorld or whatever suits you. With your Model, type Form after ID, so it looks like YourIDForm.

Now in your favourite coding software, open up the following files:






so my question is can i build a model with no database configured o table in the database????

Hi Quantico,

Yes you can create a model even if you don’t have any database. If you take a look at the CModel Class Reference, you will se that CModel has 2 subclasses :

  • CActiveRecord : this one is used to work with database
  • CFormModel : this one is used to work with forms

In the explanation you’ve inserted in your post, the author refers to a CFormModel.

Hope this helps

thanks very much Raoul, now i understand this part and i feel more into the framework, but i’m not clear about of the creation of the model, ¿can i create it from de Gii or the from the shell? because i try from the Gii and inmidiatly display a CDbExeption faild.

create CFormModel

(de nada ;) )

Maybe the best solution would be to create it from an existing CFormModel. For instance you can have a look to the blog demo which is delivered with the Yii framework (check the <YII_FRAMEWORK_HOME>\demos\blog folder). This is a good starting point if you want to learn Yii. Go to the protected/models folder and open ContactForm.php or LoginForm.php. They both inherit from CFormModel and consequently don’t require any database.

Gii or yii shell is nice, but to really understand what’s going on behind the scene, IMHO it is better to do it manually first.

hope this helps


It might be good to mention that you don’t actually need any models - a controller can exist just fine without it.;)