Yii Framework Forum: Chaining - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Chaining

#1 User is offline   alex-w 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 223
  • Joined: 25-November 10

Posted 20 June 2012 - 08:51 AM

Will more 2.0 classes allow chaining?

I was making use of some new 5.4 features trying to set the attributes of a model after it's creation.

e.g.
$model = (new MyModel)->setAttributes(array(...));


And had to extend CModel just to return the instance on setAttributes.
0

#2 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,726
  • Joined: 17-January 09
  • Location:Russia

Posted 20 June 2012 - 09:15 AM

Yes, Yii2 will use chaining more.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
1

#3 User is offline   fsb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 122
  • Joined: 09-January 11

Posted 21 June 2012 - 11:18 AM

Speaking of... does anyone have established style rules for chaining in PHP? I haven't been able to come up with anything other than fugliness.
Join the happiest place on Freenode: #yii
We've got a MrFisk the bot, hilarious banter and all kinds of other groovy stuff going on.
Comparison of Internet Relay Chat clients
Web IRC client
0

#4 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,726
  • Joined: 17-January 09
  • Location:Russia

Posted 21 June 2012 - 02:45 PM

What do you mean by style rules for chaining?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#5 User is offline   yJeroen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 94
  • Joined: 06-September 11
  • Location:The Netherlands

Posted 21 June 2012 - 03:20 PM

fsb, do you mean newlines & tabs with "style" ?

Like:
$model->something()
		->someOtherThing()
		->anotherThing();

#instead of:
$model->something()->someOtherThing()->anotherThing();

0

#6 User is offline   fsb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 122
  • Joined: 09-January 11

Posted 21 June 2012 - 04:54 PM

View PostyJeroen, on 21 June 2012 - 03:20 PM, said:

fsb, do you mean newlines & tabs with "style" ?

yes

i mean, this is just terrible:

            Yii::app()->clientScript->addPackage('sm2-muxtape', array(
                'basePath' => 'ext.Sm2Muxtape',
                'baseUrl' => bu($baseUrl),
                'js' => array('script/soundmanager2-nodebug-jsmin.js', 'page-player.js'),
                'css' => array('', 'page-player.css', 'flashblock.css'),
            ))->registerPackage('sm2-muxtape'
            )->registerCss('sm2-debug', <<<CSS
                #soundmanager-debug {
                    /* SM2 debug container (optional, makes debug more useable) */
                    position: absolute;
                    position: fixed;
                    *position: absolute;
                    bottom: 10px;
                    right: 10px;
                    width: 50em;
                    height: 18em;
                    overflow: auto;
                    background: #fff;
                    margin: 1em;
                    padding: 1em;
                    border: 1px solid #999;
                    font-family: "lucida console", verdana, tahoma, "sans serif";
                    font-size: x-small;
                    line-height: 1.5em;
                    opacity: 0.9;
                    filter: alpha(opacity = 90);
                    z-index: 99;
                    }
CSS
            )->registerScript('sm2-init',
                "soundManager.url = '$baseUrl/swf/'",
                CClientScript::POS_HEAD
            );


and the variants i've tried are no better.


if anyone has anything good, please supply PhpStorm/IDEA code style config too! that would be real swell.
Join the happiest place on Freenode: #yii
We've got a MrFisk the bot, hilarious banter and all kinds of other groovy stuff going on.
Comparison of Internet Relay Chat clients
Web IRC client
0

#7 User is offline   yJeroen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 94
  • Joined: 06-September 11
  • Location:The Netherlands

Posted 22 June 2012 - 01:51 AM

I always write the ')' on the same line as the method it's part of. Like:

Yii::app()->clientScript->addPackage('sm2-muxtape', array(
		'basePath' => 'ext.Sm2Muxtape',
		'baseUrl' => bu($baseUrl),
		'js' => array('script/soundmanager2-nodebug-jsmin.js', 'page-player.js'),
		'css' => array('', 'page-player.css', 'flashblock.css'),
	))
	->registerPackage('sm2-muxtape')
	->registerCss('sm2-debug', $css)
	->registerScript('sm2-init',
		"soundManager.url = '$baseUrl/swf/'",
		CClientScript::POS_HEAD);

0

#8 User is online   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,726
  • Joined: 17-January 09
  • Location:Russia

Posted 22 June 2012 - 02:37 AM

I'm doing it almost the same way as yJeroen does:

Yii::app()->clientScript->addPackage('sm2-muxtape', array(
                'basePath' => 'ext.Sm2Muxtape',
                'baseUrl' => bu($baseUrl),
                'js' => array('script/soundmanager2-nodebug-jsmin.js', 'page-player.js'),
                'css' => array('', 'page-player.css', 'flashblock.css'),
        ))
        ->registerPackage('sm2-muxtape')
        ->registerCss('sm2-debug', $css)
        ->registerScript(
                'sm2-init',
                "soundManager.url = '$baseUrl/swf/'",
                CClientScript::POS_HEAD
        );

Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#9 User is offline   fsb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 122
  • Joined: 09-January 11

Posted 22 June 2012 - 07:21 AM

I see. Thanks.

I'll see if I can get PhpStorm to do this for me.
Join the happiest place on Freenode: #yii
We've got a MrFisk the bot, hilarious banter and all kinds of other groovy stuff going on.
Comparison of Internet Relay Chat clients
Web IRC client
0

#10 User is offline   Jaggi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 90
  • Joined: 05-September 11

Posted 02 July 2012 - 03:55 AM

Yea I do it the yJeroen and samdark way too.
See my development site @ www.CodeTheInter.net (BETA)

Posted Image Posted Image

Quote

If you make it idiot proof, they'll build a better idiot
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users