What does this code do

Controller

$dataProvider=new CActiveDataProvider(‘User’);

	$this->render('index',array(


		'dataProvider'=>$dataProvider,


	));

View

<?php $this->widget(‘zii.widgets.CListView’, array(

'dataProvider'=&gt;&#036;dataProvider,


'itemView'=&gt;'_view',

)); ?>

This is what i did i created a table called user with username and password and used gii. then added a new field called new password. But the list view didnt show the new column("new password field"). Why what should i do.

Welcome to the forum…

As you are new to Yii I will suggest you the same that I suggest to all new Yii users…

First start with the Definitive guide to Yii, then try the Blog tutorial…

Do not just read them… do the webapp… do the code…

After these two tutorials you will not ask similar questions anymore…

As for your question… You added a new field to the database after using Gii (creating the model and CRUD)… so your code does not know for this new field… you need to add some code to use the new field… but again… instead of asking… what should I add and where… read the guides… do the examples… and you will get a grasp of Yii… and will find your answers…

You need to tell your model about the new field. :)

  1. Add the name of the field to the comments at the top.

* @var string $new_password

  1. Add the field to the rules function.

array('new_password', 'length', 'max'=>128, 'min' => 4,

   'message' => 'Incorrect password (minimal length 4 symbols).',

  1. Add the field to attributeLabels function.

'new_password' => 'New Password',

Finally, open up your _view.php file in views/your_model and add the new field to it.

Just copy the ‘password’ field and change the name.

That should be it.

jacmoe, thanks again for your hard work, but I believe that mdomba’s approach is far better. We should advice new users to read Definitive Guide, Blog Example and Cookbook articles. If not, we will be answering the same questions over and over again.

It can’t be better explained than it is in these documents. Someone one time done the hard job of writing it, so we all wouldn’t have to do this again. The only thing is that people starting play with Yii should really read those guides thoroughly and do whole examples - again, as mdomba advised. Not just pretend they read it because they looked through it. I personally spend two weeks on reading these articles and digging through forum before asking first questions here. And even so I have to admit that first one were really silly and of course - answered many times before.

It is a very good behaviour that you are trying to help as many new users as you can, because Yii is still a rather new framework and we need community to keep growing. But letting people just ask questions, not forcing them to look into guides and search the forum is in my opinion a huge waste of time and hard work other people did writing them.

You may of course disagree with me! :)

I agree with Trader… it’s nice to help other people… but if all new users posts this “basic” questions this forum will be full of posts already explained and answered… and difficult to search

[color="#000000"]

As one wise saying goes[/color]:

So all newcommers really should first grasp the basics of Yii ( learn how to fish :) )… do the basic application… add some model/crud… ideally do the blog tutorial… and most of the “lame” questions will be answered there… in the meantime they will get to some new ideas and “interesting” questions that they will ask in the forum…

@Trejder - Before Yii I haven’t used objects in PHP… so I first got a good read about objects in PHP in general… then took the definitive guide and read it a few times… trying to make some examples… only after two month I felt confident to ask and even respond to question on the forum…

You have good points.

But it took me shorter time to write down what you need to do than you spent on telling him to look in the official guides.

And the guide is not absolutely clear in how you’d do that: add a new field manually.

Of course, you need to study the official documentation.

But - in my experience (and I have a lot of it from being a moderator with 18 K posts on ogre3d.org) - it’s a ‘good thing’ to explain what’s already explained in new ways.

Maybe the OP did read the docs?

That doesn’t mean that he understands how it works, though. ;)

Often, you need to nudge people in the right direction.

Besides, you don’t have to go RTFM (read the friendly manual) on people all the time…

At least, not as a stand-alone answer. :)

I hope that this is not the only reason why people help each other here and really hope that they will do it even when Yii is grown up. I must admit that your words are right in many aspects but sometimes reading docs is not enough. To programm with a framework one must feel it, one must change the way of his thinking. Sometimes I read documentation but can’t understand it and it’s really good to have someone to ask a question or two ;) .

Perhaps the word [size="4"]recommended[/size] should be added to this hint in the start page

I think the role of The Definitive Guide has been played down to much in the new web site.

/Tommy

Just to say that Mdomba and I were posting at the same time. ;)

The definitive guide is great.

Not everyone waits until they’re ‘worthy’ to post their first question.

We’re all different.

But one of the main reasons for me in deciding to go with Yii is the forum.

A friendly community is a tremendous asset to any project.

It doesn’t build itself, but I think the Yii community is on the right track.

EDIT : It works now i forgot to add it in _view

First of all after reading on the web about no support for Yii or bad support i am shocked at the replies i got. thanks for all of you. I do agree i have to read through the tutorial and guides before posting but here is my defense. I was going through a book on yii called Agile development with yii 1.1 and PHP5 and i stuck up at this point so decided to ask. The solution given above didnt work. none of the Gii generated views have this new field. This is my model


<?php


/**

 * This is the model class for table "user".

 *

 * The followings are the available columns in table 'user':

 * @property integer $id

 * @property string $username

 * @property string $password

 * @property string $newpassword

 */

class User extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @return User the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'user';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('username, password, newpassword', 'required'),

			array('username, password, newpassword', 'length', 'max'=>50),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('id, username', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'id' => 'ID',

			'username' => 'Username',

			'password' => 'Password',

			'newpassword' => 'New Password',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);

		$criteria->compare('username',$this->username,true);

		return new CActiveDataProvider(get_class($this), array(

			'criteria'=>$criteria,

		));

	}

}



I had the same situation. Before Yii I had a quite experience with object oriented programming taken from Delphi, but it was quite different than in PHP. In pure PHP I started with pure procedural coding before Yii. I also started with analysing demo apps’ code and guides. Yeah - it was quite a pain in the ass, but I refused to bother others before I run out of any other option. :)

Of course, not! I’m trying to help others, thinking that others will at least try to help me, when I’m really stacked! :) And I believe most other Yii users and forum posters thinks quite similarly.

BTW: Yii well never grow enough! :) Until we’re gonna rule whole world, forcing all other PHP frameworks (what am I saying - all other programming languages!) to distinct, it will never be enough! :D :D :D

Quite off-topic, but I’m shocked! Where did you read about no support for Yii or bad support? Show it to me, please. Because I personally think that Yii support (this forum, guides) are one of the best I ever found for any project I ever worked over

I’m very happy that you finally found solution to your problem! :)

Before beginning studying on yii yesterday i did some research on how IS Yii COMPARED TO Other PHP frameworks. I am a cakephp (+ 2 other custom framework) programmer. during that a few blogs had posted that it was too young and didn’t have enough support. Also in StackOverflow i found only 140 topics under Yii-framework.

That explains much. But since you heard that Yii lacks of support and after joining us, you see that this is not true, then this could lead us to a conclusion, that other people, forums, organisations may not intentionally (or sometimes intentionally, if we’re talking about concurence) lead user into confusion or even promote wrong picture of Yii. Sad, but true.

see You have 139 posts and the yii staff has 761. need i say more but sure it’s growing. One more problem the Official pdf does not explain where to create a file(filters , widgets) also module is too confusing(how to use them). could some one explain

Yii Staff, including Qiang, Framework Creator and other top rated members has over 2000 posts (Qiang - over 5500). See here for more details. But is it related in any way to what we are discussing here? Because I don’t see any relation…

Or no! I see a very good relation. You have only ten posts and half of them is arguing how Yii documentation is badly written! I wouldn’t consider this as a good start among Yii community!

Yii is a programming framework. Programming is studying, analysing, searching, testing, checking etc. Documentation should only be a background for your own researches. If you are looking for a perfect documentation that will lead you by-hand, will solve any of your problems and ask all your questions without any or with as small effort from your side, as it is possible - then you are probably in a wrong place.

Guides and documentation are written by the same people, who actually create this fabulous framework. They are not being paid for neither framework nor documentation. All they do is their free will to spend free time on development of this project. Starting your career from yelling that documentation is bad is at least a bad behaviour.

P.S.: If you are starting with filters, widgets and modules which are rather medium intermediated issues, without building basic app, and researching how things are organized and how everything works in Yii, I am not surprised that you have more problems than successes and that you comply on how badly documentation is written.

My personal advice: Spend a week or two on reading all guides and rest of documentation thoroughly, read as many forum posts, as possible, examine all demos, run all examples, maybe read a book written about Yii. Then get back to this discussion and we will see, if you are still thinking that documentation is badly written.

And…? :)

I think, even when you consider the age of the project, that Yii has a solid amount of documentation.

It’s got a guide, API docs, Wiki, forum.

A forum is a great asset.

(Other frameworks I know of (not pointing at any framework in particular) uses mailing list… Hello? We’re not in the 90’ies anymore, are we?)

If you need anything, feel free to ask.

And, please:

Be a bit more specific than this:

That’s very close to ‘Someone, please help me!!’ - and it does nothing but trigger a lack of interest on my part.

I am sure that other people feels the same way.

Put some effort into asking, and people will put some effort into answering.

It’s self-evident, isn’t it? :)

If you need help on how to ask, ask. ;)

A bit OT, but as you commented the number of post…

Only looking at the number of posts does not say anything at all… you should take a look when the user has registered to the forum… and at the user profile page on the "active post" line there is a calculation of number of posts per day that is an effective number telling who is active on the forum…

For example even as I have >700 posts, I have 1.84 posts per day, Trejder even as he have ~130 posts, has 2.43 posts per day… so if he registered at this forum when I was, and if he was active all the time like is now… he would have now the double of my post…

Another thing is the quality of posts… someone can just post questions (or complaints) and have a high number of posts… another one can post just answers trying to help but have small number of post…

So in the end… it’s useless to compare users by number of post… you should compare users by the quality of posts

When you post a question…

you need to understand that anybody that is answering you… is taking his time to try to help you the best way he can

if it would be not this case… he would not post on your thread at all…

This forum is very active and has a high volume of new posts per day, so just reading all the posts takes much time… not to mention thinking of the solution… trying the solution… writing the answer… and all users has their job, life, etc.

If you stick around on this forum you will notice that here is a very nice community of very good programmers and very good people… that helps each other on solving very different kinds of problems…

Sorry to all if it’s too OT… but that’s my two cents for this thread… :)

One more thing… the documentation is not written in stone… and any time that someone suggested/requested a better description/documentation… it was examined and implemented…

100% truth!