Default helper params

I'd like to redefine some static params of CHtml class ($beforeRequiredLabel, for example).

Where's the best place to do it?

(as for now, I'm setting their values in my module's init() function. Am I wrong?)

The init() function is good. If they are something you'll reuse, I suggest building your own class which extends CHtml to your liking.

Hi,Jerry.

I extend CHtml and redefine $beforeRequiredLabel and $afterRequiredLabel as following.



	public static $beforeRequiredLabel='<span class="required">*</span>';


	public static $afterRequiredLabel='';


But it didn't work.

How do you change CHtml default properties by exntending it?

Extending it would not work for extension or widgets that still use CHtml.

But the static members  $beforeRequiredLabel and $afterRequiredLabel are signed as public thus you can simply change its value at the beginning of each request.



CHtml::$beforeRquiredLabel = 'yourValue';


That's correct. Existing code wouldn't be affected by an overriden method.

But if you're building your own widgets/extensions, overriding will work fine.

Hi,Dave.

Quote

CHtml::$beforeRquiredLabel = 'yourValue';

It works.

I put it in index.php, so that effects all controllers.

Thanks.

And Jerry, thanks for your explanation.

Anytime dude.

I've got a class in my extensions library that builds all of the form stuff out for me and then some.

It’s called CPSActiveWidgets and will be in the next release of my extension library.

When building forms out, you can use something like this:



		<fieldset>


			<legend>General Information</legend>


			<?	


				$_arDisabled = array( 'disabled' => true );


			


				//	Lay out our form...


				echo CPSActiveWidgets::simpleActiveBlock( CPSActiveWidgets::PSAWFT_TEXT, $_oItem, 'inv_uid', $_arDisabled, 'ID' );


				echo CPSActiveWidgets::simpleActiveBlock( CPSActiveWidgets::PSAWFT_DROPDOWN, $_oItem, 'inv_type_uid', array( 'prompt' => 'Select One...', 'onchange' => 'buildSpecifics(this);' ), 'Type', null, CHtml::listData( InventoryType::model()->findAll(), 'inv_type_uid', 'type_name_text' ) );


				echo CPSActiveWidgets::simpleActiveBlock( CPSActiveWidgets::PSAWFT_TEXT, $_oItem, 'name_text', null, 'Name' );


				echo CPSActiveWidgets::simpleActiveBlock( CPSActiveWidgets::PSAWFT_TEXT, $_oItem, 'alt_name_text', null, 'Alternate Name' );


			?>


		</fieldset>


It does all the <DIV> tags and makes the input field. In addition, you can make extension widget fields (from my library like jQuery UI widgets) the same way.

Take care and good luck.

– J

Quote

Hi,Dave.

Quote

CHtml::$beforeRquiredLabel = 'yourValue';

It works.

I put it in index.php, so that effects all controllers.

Thanks.

And Jerry, thanks for your explanation.

Even if it works i think to put it in index.php is not a good idea.

I would suggest the following:



class BaseController extends CController {


  public function init()


  {


    //make youre changes to CHtml here 


    parent::init()


  }


}


Than extend every controller you use from BaseController instead of CController. If you need furhter changes that should affect all controller you place them there too.