How much do you use API?

sorry for hijacking the thread for another question.

But since it seems that some of you use Netbeans I would like to ask whether there is some way with netbeans to get code completion on the column names in the model. Yii generates the following phpDoc but Netbeans seems to ignore that.




	/**

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

	 * @var integer $id

	 * @var string $name

	 * @var string $created

	 * @var string $updated

	 */



does anyone know how to get netbeans to work with that?

I think Netbeans doesn’t read any random phpdoc, just ones that are connected to declarations.




/**

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

 * @property integer $id

 * @property string $name

 * @property string $created

 * @property string $updated

 */

class MyModel extends CActiveRecord {

  //…

}



thank you so much

that did it

it’s one of the simple things that can greatly enhacne your productivity

I just can’t remember column names in 50 tables or so :)

You can also cast Yii::app()->mailer to for example (PhpMailer)Yii::app()->mailer to enable ctrl + space for that object.

Where do you do this in Komodo Edit? I only see a place to add an API catalog in XML format.

Umm… forget it. I just switched to NetBeans. Wow. Didn’t know what I was missing.

Dave

By doing


(PhpMailer)Yii::app()->mailer

you aren’t just helping IDE but converting Yii::app()->mailer to PhpMailer type. I’m not sure if it takes time to do it but generally it’s not the right thing to do.

When you cast an object to an object, then nothing happens; you just get an object. Not very interesting. But if you convert anything else to an object, then you get a new instance of stdClass.

One of the very useful uses of casting to object with Yii is the casting of arrays, which for us object oriented types, makes for some interesting (more concise and readable) alternatives to the way Yii has been coded.




  $user = (object) array('name' => 'John', 'age' => 18);

  echo $user->name;



Here’s a good page to get started on the fun – and very tight readable code – you can produce with casting. (For those wondering what’s going on, try using FirePHP on the cast.)

And this is useful too:




$obj = new stdClass();

$obj->data = "Blah";



(Caveat: Note that numeric "keys" in arrays cast to objects will not work. Though this would be inadvisable in any case: $x->3?)

auxbuss,

I think numeric keys will work with the following workaround: $x->{‘3’}. Not tested though.

Even if it does work – I don’t believe it does – the syntax is enough reason not to use it! Like perl and c++ :)

You’re right. I just confirmed it: array items with numerical keys are not accessible once array is converted to stdClass.

The interesting thing is that the conversion does not drop these values.




$var = (object) array('zeroIndexed', '3'=>'explicitIndex', 'key'=>'value');


object(stdClass)[1]

  string 'zeroIndexed' (length=11)

  string 'explicitIndex' (length=13)

  public 'key' => string 'value' (length=5)



They just happen to be.

That was just an example. If Yii::app()->mailer is not an instance of PhpMailer then it makes no sense. What I wanted to point out is that you can tell your IDE the class you are working with.

Can you please advice where should I put the vdoc code




/* @var $db CDbConnection */



to let Netbeans can auto complete Yii::app()->db or other frequently used variable inside the main.php?

Thanks.


/* @var $app CWebApplication */

$app = Yii::app();

$app-> 



Show only methods.

How add properties in hint list ?

henqi

Just after the variable you do want to have completion for.

icevan

Properties like what?

pestaa, auxbuss

Another good thing is converting objects to arrays: (array)$object… but the point was about converting to the same type (PhpMailer in our case) and not to object.

@samdark: Apropos casting an object , you said “I’m not sure if it takes time to do it but…”. I replied to that and raised you ten. But you are right, I forgot I was in PHP-land.

properties like propertie :)

example:




/*@var $user CWebUser */ 

$user-> HINT LIST



Hint list show getIsGuest()

i want see isGuest

It is not possible with the current codebase. Yii supports this getter approach, which is not understandable from an editor’s point of view.

I hope in future eclipse team improve it