Blog Tutorial - Strange things in v1.0.6

Some Code in the tutorial doesn't work with version 1.0.6.

E.G.

[tt]public function actionCreate()

{

    $post=new Post;

    if(isset($_POST['Post']))

    {

        $post->attributes=$_POST['Post'];

        if(isset($_POST['previewPost']))

            $post->validate();

        else if(isset($_POST['submitPost']) && $post->save())

            $this->redirect(array('show','id'=>$post->id));

    }

    $this->render('create',array('post'=>$post));

}[/tt]

I had to change this code to:

[tt]public function actionCreate()

  {

    $model=new Post;

    if(isset($_POST['Post']))

    {

        $model->attributes=$_POST['Post'];

        if(isset($_POST['previewPost']))

            $model->validate();

        else if(isset($_POST['yt0']) && $model->save())

            $this->redirect(array('show','id'=>$model->id));

    }

    $this->render('create',array('model'=>$model));

  }[/tt]

The name of the submit-button has somehow changed to "yt0". I don't know why. Any idea, what might have gone wrong?

BTW: The content-textarea field has no "required"-mark in my installation, although I didn't change the database structure.

It should be working. Please watch the 'create' view then.



<?php $this->renderPartial('_form', array(


        'post'=>$post,


        'update'=>false,


)); ?>


A variable $post is passed from the controller. And in the '_form' view,

<div class="row action">


<?php echo CHtml::submitButton($update ? 'Save' : 'Create', array('name'=>'submitPost')); ?>


<?php echo CHtml::submitButton('Preview',array('name'=>'previewPost')); ?>


</div>


the button name is 'submitPost', not 'yt0'. May be your controller and view are mismatching.

Thank you. Some things seem to go wrong with yiic in v1.0.6. In the generated code there is always $model passed, not $post.

<?php echo $this->renderPartial('_form', array(


	'model'=>$model,


	'update'=>false,


)); ?>

Therefore I made the change.

And the submit-Button gets no name by default:

<?php echo CHtml::submitButton($update ? 'Save' : 'Create'); ?>

So it becomes "yt0"; which might be a weird jQuery influence.

View Source (Post Comment):

<div class="action">


<input type="submit" name="yt0" value="Create" /></div>


In the source code of blog demo I found this:

<li><a href="#" id="yt0">Logout</a></li>


and this:

<script type="text/javascript">


/*<![CDATA[*/


jQuery(document).ready(function() {


jQuery('#yt0').click(function(){jQuery.yii.submitForm(this,'',{'command':'logout'});return false;});


});


/*]]>*/


So there's something wrong with the console script. A bug? Or a feature?

If you follow the tutorial, you must change the name of passed variable “$post” to “$model”, or else Yii throws weird errors.

If it was an intended change, why is it undocumented???

Addendum:

I’ve just recreated the blog skeleton with yiic shell in v.1.05 and 1.0.6. Here are the differences:

In Post Controller v. 1.0.6:

<?php public function actionCreate()


	{


		$model=new Post;


		if(isset($_POST['Post']))


		{


			$model->attributes=$_POST['Post'];


			if($model->save())


				$this->redirect(array('show','id'=>$model->id));


		}


		$this->render('create',array('model'=>$model));


	} ?>

In View PostCreate:

<?php echo $this->renderPartial('_form', array(


	'model'=>$model,


	'update'=>false,


)); ?>

Other code in v.1.0.5:

<?php public function actionCreate()


	{


		$post=new Post;


		if(isset($_POST['Post']))


		{


			$post->attributes=$_POST['Post'];


			if($post->save())


				$this->redirect(array('show','id'=>$post->id));


		}


		$this->render('create',array('model'=>$post));


	} ?>


  //View PostCreate:

 

  <?php echo $this->renderPartial('_form', array(

&#039;post&#039;=&gt;$post,


&#039;update&#039;=&gt;false,

)); ?>

In my opinion, it’s a bug with yiic shell in version 1.0.6!!!

OK, I understand your situation. What I am talking about is the code of the blog demo, whereas you are talking about the generated code by yiic and the document. There is no inconvenience since the variable is consistently $model from the controller to the view (create, _form), thus we do not need to modify it to $post. On the contrary, as the document has much abbreviation and is based on the previous version of yii, it should be modified to match 1.0.6. In conclusion, it is not a bug of yiic, but a bug of the documentation, I think.

Well, I understand, that the new generated code has advantages regarding re-usability. So ist is not bad. But what I find really bad is, that this change hasn't been documented. A well designed and easy to follow tutorial is essential for spreading the Yii framework to a wider audience. People don't have always time to test and inspect all code, and they might go away to CodeIgniter or CakePHP. This way, Yii loses users. I personally, it's a great framework and ranges under the Top 5. The only thing I'm missing are more core helpers like CodeIgniter has. I'm lazy and don't want to implement all that stuff by myself. :wink:

Conclusio: Someone should update the tutorial document as soon as possible.

Thanks to mocapapa for explanation. We will update the blog demo and tutorial to match this change.

Quote

...  A well designed and easy to follow tutorial is essential for spreading the Yii framework to a wider audience. People don't have always time to test and inspect all code, and they might go away to CodeIgniter or CakePHP. ...

Conclusio: Someone should update the tutorial document as soon as possible.

Hi everyone,

I really like Yii - I like it cause it generates a modifiable  site instantly and because of its CRUD features.

HOWEVER … learning it has been VERY discouraging (in fact, I gave up!).

What would make a tutorial leave important details out, or not having the main video tutorial not explain fully, or not be up-to-date  (or go too fast) is beyond me.

If Yii is targeted at PHP pros only … it will soon die out. The secret of a successful framework IS its learning curve. No matter how good it is –  if it can NOT be learned easily potential users will just move on to CodeIgniter, whose forum has much to teach Yii (for it gladly welcomes newbies by answering specific questions with specific teachings – not just replying with “read the guide”).

No disrespect to anyone – I express my thoughts on this cause I care that this framework succeed.

But everyone here knows that in the time it takes to learn how to do the blog demo, a dozen sites can be already made with CI — and all because lack of introductory instructions.

I cannot see how anyone can fully complete the blog demo tutorial (via its video or guide) "without"  help from the forum.

tutorials should tested on a newbie FIRST before releasing it. The exception is when its creator sincerely wants newbiew to learn – then all steps will be FULLY documented, and necesary explanations given.

I think that the developers of Yii should just STOP enhancing, for now, and concentrate more on creating easier to understand, and more updated, tutorials (text and videos).

… otherwise, interest on Yii will slowly dissolved.

I truly feel that Yii is such a fine framework – yet neither CI or Kohana, or developers of other frameworks, ever worry about Yii as a competition … because it is so had for a beginner php programmer to learn it.

Nevertheless, if Yii is targeted at php pros MAINLY who will take months to analyze each page to figure it out … then I will stand aside and shut up.

Of course I understand what you said. But for now, yii is progressing so rapidly as to release itself once a month. The documentations should be written when the target is stable, otherwise we should pay useless man-hour over it. Please wait and see for a while it slows down, as it is going to be released once a couple of month. Then, the effort will be shared for the documentation, I hope.

BTW, I think "Read the guide xxxx" is the right answer, not an answer that looks down upon someone.

Quote

... BTW, I think "Read the guide xxxx" is the right answer, not an answer that looks down upon someone.

True – however, most of the commands in the guide do NOT contain real life example. Only a PHP Expert can make sense of it.

It does not require much effort to give a real example following a command listing

But fear not,  soon I will be an expert on Yii – with the help of this forum (as slow as it is) and from the help of the developers (you included).

Then while you guys perfect Yii, I will break down the instructions for others to understand – and together we will make Yii a true Yii-Haw!!

I like and enjoy sharing and teaching – feels good.

:)

long live Yii !!!