YII ajax capabilities

Greetings!

(As it comes out, I cannot add links to my post, you have to copy-paste those)

I’m new to the YII framework and have been on IRC few days asking some questions. The thing is, I have used QCodo for several years now. Really love the framework, but it’s quite inactive. So, now I’m looking around for which framework might be a substitute.

I’ve checked out the blog tutorial and some other demos available. But the get a better picture of the framework, I have some questions. Mostly regarding to the ajax-related functionality.

  1. How would you implement something like that in YII:

examples.qcodo.com/examples/basic_ajax/intro.php

There is a button. When you click on it, one label on the page will be changed.

  1. How about this one:

examples.qcodo.com/examples/dynamic/inline_editing.php

You can change values inline. Note, that when I order the list by last name and modify one last name, it is automatically ordered accordingly.


I like that YII has so many helper modules for common things. For example authentication. Regarding auth, is there an easy way to allow/disable buttons on a page? E.g. admin can see "Save" button, guest cannot (but the page itself is visible to both).

BTW, is there anyone who has tried QCodo (or QCubed) and now uses YII (or vice versa)? I would like to know why you switched?

Thanks in advance!

I’m new, too. But when I was trying to learn Yii, I put together something a lot like the page you link to see how Ajax works in Yii. To do that, I built on this example. Someone can correct me if I’m wrong, or if there is a better way, but I did something like this:

(1) In your view file:


 

<div id="somediv">Click the button to change the message</div>


<?php

  echo CHtml::ajaxButton("Click me",

     Yii::app()->createUrl("somecontroller/ajax"),

     array("update" => "#somediv"));

?>



(2) In controller somecontroller:




function actionAjax(){

  echo "Hello, world.";

  Yii::app()->end();

}



(3) In controller somecontroller, make sure there is a rule allowing action Ajax to be invoked.

I have to think about your second example, but this one is fairly easy, and there are different ways of doing it. In your view, you can include whatever php you want, so you can:




<?php if (!Yii::app()->user->isGuest): ?>

  Only signed in users can see this!

<?php endif; ?>



However, a lot of the widgets included in Yii seem to have easier ways of doing this. For example, menus have a "visible" property that you can set to some condition. I actually have this in one of my views:




if(!Yii::app()->user->isGuest){

	$this->menu=array(

		array('label'=>'Upload document', 'url'=>array('upload')),

		array('label'=>'Manage Documents', 'url'=>array('admin'), 'visible'=>!Yii::app()->user->getState(limited)),

	);

}



First, the menu only shows up if the user is signed in. Second, the admin menu only shows up if the signed in user isn’t limited (my app has two kinds of authenticated users: limited and unlimited.)

Of course, this only controls the visibility of the controls. The actual access control is implemented in the controller.