Articles Section

Ok, I use the gii to create a model called articles and then I created a crud. This is my db table layout.

id / Article ID

title / varchar(50) | Title of article

body / text | The body of the article

creates / datetime | the date and time the article was created

modified / datetime | the date and time the article was modified

The problem is that the created field should be added when the article is created, Then this never changes. and then when the article is updated (editing). The modified field gets updated with the new date and time. How ever the problem is that when I created the crud. It’s asking for input for these 2 fields. and it shouldn’t. Sense I never did this kind of coding before I didn’t know how to change them. I’m all looking for a way to attach a file and/or image to this article all so. PLEASE can any one help.

Just delete unnecessary form fields from the generated view file and validation rules in model’s rules() method.

Yii is an application development framework for web developers, not a CMS or a website generator. In order to use it effectively you need a solid knowledge of PHP and HTML and some basic understanding of object oriented programming and Model-View-Controller pattern.

Take a look here.

That doesn’t tell me how to edit the save. When I save the article. How and where do I edit that information at. I mean that when I click the save button. It saves a new article or it saves the updated article. Where do I edit code for this.

Implement beforeSave() method in your model class to set create/update timestamp. Check isNewRecord property to decide if it’s a create or update operation.

Sorry, I don’t under stand.

  1. The form for uploading an image doesn’t match what I have and well I’m all so lost on this.

  2. And I have no idea on where to use the beforeSave() and isNewRecord() methods. or even what to add to the methods to get it to work. I wish I could find better tutorials or videos on this. Some thing that will show me step by step.

Hello. Don’t think it’s difficult. Begin by spending some hours or several days on Larry Ullman’s tutorial series (the link is present in the tutorials page). They are really step by step, and I advise you to read ALL the comments to each episode before hopping to the next one.