Yii Framework Forum: in my fist aplication in yiii how i crate a model whit no database - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

in my fist aplication in yiii how i crate a model whit no database Rate Topic: -----

#1 User is offline   quantico 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 05-May 11
  • Location:Guatemala

Posted 05 May 2011 - 03:19 PM

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.

Tutorial:

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:

protected/controllers/YourIDController.php
protected/models/YourIDForm.php
protected/views/YourID/edit.php
protected/views/YourID/index.php
protected/views/YourID/show.php

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

#2 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 637
  • Joined: 29-November 08
  • Location:Paris, France

Posted 05 May 2011 - 04:47 PM

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
Posted Image
0

#3 User is offline   quantico 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 05-May 11
  • Location:Guatemala

Posted 05 May 2011 - 06:01 PM

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.
0

#4 User is offline   adsmail27 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 30-April 11

Posted 05 May 2011 - 07:32 PM

create CFormModel
0

#5 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 637
  • Joined: 29-November 08
  • Location:Paris, France

Posted 06 May 2011 - 06:35 AM

(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
8)
0

#6 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 06 May 2011 - 08:35 AM

It might be good to mention that you don't actually need any models - a controller can exist just fine without it.;)
"Less noise - more signal"
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users