I try to extend BaseHtml class by follow this tutorial
But is not find the BaseHtml extended class
namespace common\components;
class Html extends \yii\helpers\BaseHtml {
}
this is the error:
Class 'yii\helpers\BaseHtml' not found
Where I am wrong?
Update
I try to copied the Html.php file locate in Helpers and is still the same
<?php
/**
* #link http://www.yiiframework.com/
* #copyright Copyright (c) 2008 Yii Software LLC
* #license http://www.yiiframework.com/license/
*/
namespace yii\helpers;
/**
* Html provides a set of static methods for generating commonly used HTML tags.
*
* Nearly all of the methods in this class allow setting additional html attributes for the html
* tags they generate. You can specify, for example, `class`, `style` or `id` for an html element
* using the `$options` parameter. See the documentation of the [[tag()]] method for more details.
*
* For more details and usage information on Html, see the [guide article on html helpers](guide:helper-html).
*
* #author Qiang Xue <qiang.xue#gmail.com>
* #since 2.0
*/
class Html extends BaseHtml
{
}
And now I have another problem. It not find BaseHtml fro the original class
vendor/yiisoft/yii2/helpers/Html.php
Solution found
I refactored the override file and phpStorm change me the path to BaseHtml in vendor/yiisoft/yii2/classe.php
BaseHtml.php should be under /vendor/yiisoft/yii2/helpers/ folder.
If it's not there, you will need to update your vendors or try to copy file BaseHtml.php to your yii2/helpers at yii2 repo: https://github.com/yiisoft/yii2/blob/b7b9c8ba40d65ec7c745ee639a8a6eb96e7aea75/framework/helpers/BaseHtml.php
Hope it helps.
Related
I came across this weird behavior while using NumberFormatter in AS3.
It's important to understand that I need to use NumberBaseRoundType.UP because I need to use NumberBaseRoundType.DOWN when applying a credit.
Considering the rounding precision that has a value of 2, I guess the NumberFormatter shouldn't change my number. In the example below, 2.43 once formatted become 2.44..!
So the Math.pow(...) is not the solution I'm looking for PLUS, I am very interested to understand what and why this is happening. THANKS!
var roundUp:NumberFormatter = new NumberFormatter();
roundUp.rounding = NumberBaseRoundType.UP;
roundUp.precision = 2;
trace(roundUp.format(2.41)); // Output : 2.41
trace(roundUp.format(2.42)); // Output : 2.42
trace(roundUp.format(2.43)); // Output : 2.44 <-- ???
trace(roundUp.format(2.44)); // Output : 2.44
trace(roundUp.format(2.45)); // Output : 2.46 <-- ???
trace(roundUp.format(2.46)); // Output : 2.46
This is not a complete answer. But to start off with which NumberFormatter class are you using (what's the package it comes from). Some of the source is available, some of it is contained in the player itself and isn't accessible, but in looking at the on included in Spark from the 4.6 framework it includes this class level comment that gives some insight:
/**
* The NumberFormatter class provides locale-sensitive formatting
* and parsing of numeric values. It can format <code>int</code>,
* <code>uint</code>, and <code>Number</code> objects.
*
* <p>This class is a wrapper class around the
* flash.globalization.NumberFormatter class.
* Therefore, the locale-specific formatting
* is provided by the flash.globalization.NumberFormatter.
* However, this NumberFormatter class can be used in MXML declarations,
* uses the locale style for the requested Locale ID name, and has
* methods and properties that are bindable.
* </p>
*
* <p>The flash.globalization.NumberFormatter class use the
* underlying operating system for the formatting functionality and
* to supply the locale-specific data. On some operating systems, the
* flash.globalization classes are unsupported, on these systems this wrapper
* class provides fallback functionality.</p>
*
* #mxml <p>The <code><s:NumberFormatter></code> tag inherits all of the tag
* attributes of its superclass and adds the following tag attributes:</p>
*
* <pre>
* <s:NumberFormatter
* <strong>Properties</strong>
* negativeNumberFormat="<i>locale and OS dependent</i>"
* />
* </pre>
*
* #includeExample examples/NumberFormatterExample1.mxml
* #includeExample examples/NumberFormatterExample2.mxml
*
* #see flash.globalization.NumberFormatter
*
* #langversion 3.0
* #playerversion Flash 10.1
* #playerversion AIR 2.5
* #productversion Flex 4.5
*/
Ultimately though it states that the player uses the underlying OS in some way to achieve the formatting. It is certainly a strange problem but I'd be surprised if this wasn't ever caught before and an explanation hasn't been posted or at least a bug report if it is in fact an issue in flash player. Some more details on your SDK version and player version may help, also have you tried fiddling with either of these is there any change in results?
Also depending on what you're attempting to achieve you may be able to just get around the issue by writing your own class to deal with doing the formatting for this case if it's just a one off scenario that you need to deal with this, if it's more of a system wide used thing that needs more of the functionality of the NumberFormatter class I could understand wanting to resolve the underlying issue.
This question already has an answer here:
Custom HTML tag attributes are not rendered by JSF
(1 answer)
Closed 2 years ago.
I am using Primefaces 3 in JSF 2 to make a search box. I need to add a non-standard attribute (x-webkit-speech) to the control so you would have something like this...
<p:autoComplete x-webkit-speech="x-webkit-speech" ... />
Since this attribute isn't part of the autoComplete control JSF gives me a 500 error. But when I remove it, the page renders fine. In general, how do you specify pass through attributes on a JSF tag so they are ignored?
JSF by design ignores all custom attributes when rendering HTML.
If you're already on JSF 2.2+, simply specify it as passthrough attribute:
<html ... xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
...
<p:autoComplete a:x-webkit-speech="x-webkit-speech" ... />
If you're not on JSF 2.2 yet, then you need a custom renderer. This is in case of PrimeFaces <p:autoComplete> (and all other components) fortunately relatively simple. It's sufficient to override just the renderPassThruAttributes() method wherein you add the new attribute which you'd like to render to the attrs argument and finally delegate to the super method.
E.g.
package com.example;
import java.io.IOException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.primefaces.component.autocomplete.AutoCompleteRenderer;
public class MyAutoCompleteRenderer extends AutoCompleteRenderer {
#Override
protected void renderPassThruAttributes(FacesContext facesContext, UIComponent component, String[] attrs) throws IOException {
String[] newAttrs = new String[attrs.length + 1];
System.arraycopy(attrs, 0, newAttrs, 0, attrs.length);
newAttrs[attrs.length] = "x-webkit-speech";
super.renderPassThruAttributes(facesContext, component, newAttrs);
}
}
To get it to run, register it as follows in your webapp's faces-config.xml:
<render-kit>
<renderer>
<component-family>org.primefaces.component</component-family>
<renderer-type>org.primefaces.component.AutoCompleteRenderer</renderer-type>
<renderer-class>com.example.MyAutoCompleteRenderer</renderer-class>
</renderer>
</render-kit>
(you can find out the component family and renderer type by looking at the source code of AutoComplete class, they're specified as COMPONENT_FAMILY and RENDERER_TYPE constants in there)
No, the #FacesRenderer annotation simply won't work when the purpose is to override custom renderers which are by itselves already registered in a faces-config.xml.
The most Tags can be extended, using the Attribute-Tag from JSF-Ext.
<html xmlns:h="http://java.sun.com/jsf/html" xmlns:e="http://java.sun.com/jsf/ext">
<!-- ... -->
<h:inputText id="name" value="#{bean.name}">
<e:attribute name="placeholder" value="My Name"/>
</h:inputText>
<!-- ... -->
</html>
You can configure it via maven:
<dependency>
<groupId>com.intersult</groupId>
<artifactId>jsf-ext</artifactId>
<version>2.2.0.1</version>
</dependency>
JSF-Ext is a library from http://www.intersult.com/wiki/page/JSF%20Ext
I am not sure if this is possible at all. I would add those attributes on the client side using javascript or jQuery.
You can put el expressions into your javascript code if you want to integrate server-side stuff.
I have a custom component called ButtonPanel written in Actionscript. Basically it's just a panel that displays a mx:ButtonBar in the upper right of the mx:Panel title bar and responds to the clicks of the buttons in the bar.
A ButtonBar has three styles available for the buttons: buttonStyleName, firstButtonStyleName, and lastButtonStyleName. I want to write these styles for the ButtonPanel so that if it is declared as such:
<comp:ButtonPanel buttonStyleName="myButtonStyle" ... />
then the ButtonPanel will pass the style through and set the corresponding style of the ButtonBar.
I really have no clue where to start on this because I've never messed with defining styles. Can someone help?
What you refer to as "pass-through" styles are actually called inheriting styles. The solution to your question is in fact quite simple.
You use the style metadata on your custom component to declare that ButtonPanel has a stylename called 'buttonStyleName':
[Style(name="buttonStyleName", inherit="yes")]
public class ButtonPanel extends Panel {
....
}
Note the 'inherit' flag which is set to true: this will make sure that any component inside your custom Panel that has the same style will inherit the value that you've given to that style at the Panel level.
Setting this metadata will make sure that FlashBuilder will suggest buttonStyleName as a style and not as a property (as would happen with Sam's solution).
Edit: already defined styles
I didn't realize at first that you were referring to the mx ButtonBar (as it's not explicitly mentioned). The reason this is not working for you is that mx:ButtonBar already has these styles defined as not inheriting. Look at the source code:
[Style(name="firstButtonStyleName", type="String", inherit="no")]
[Style(name="buttonStyleName", type="String", inherit="no")]
[Style(name="lastButtonStyleName", type="String", inherit="no")]
Because of this the compiler will complain when you try to override that definition in your custom Panel, because it simply wouldn't know which of the contradictory instructions to pick. So we'll have to do a little more work if you want to stick with mx:ButtonBar.
First define the styles on ButtonPanel exactly as they are defined in mx:ButtonBar so they have the same signature (you can just copy/paste the three lines above). This will shut up the compiler but the styles won't be inherited anymore, right?
So we'll have to pass them on manually: in your custom Panel skin, override the updateDisplayList() method and - assuming that the ButtonBar's id is 'buttonBar' - add the following:
private const buttonStyles:Array = [
"firstButtonStyleName",
"buttonStyleName",
"lastButtonStyleName"
];
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
if (buttonBar)
for each (var buttonStyle:String in buttonStyles)
buttonBar.setStyle(buttonStyle, getStyle(buttonStyle));
//some other code
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
This will take the styles from the host Panel and pass them on to the ButtonBar.
In order to pass these styles through, you only have to store them as string variables, and then pass them to the internal ButtonBar.
<mx:ButtonBar ... buttonStyleName="{buttonStyleName}" ... />
[Bindable]public var buttonStyleName:String;
If these two lines of code don't explain it fully to you, let me know and I can flesh out my example.
I keep encountering many references to style protochain in the documentation about css in flex. I tried to look it up but I couldn't find any relevant information. Can anyone tell me what does the class StyleProtochain do?
In its source code, there is the following comment.
/**
* #private
* This is an all-static class with methods for building the protochains
* that Flex uses to look up CSS style properties.
*/
Cool, it tells me that there are a couple of methods for building the protochains, now I am supposed to know what it does, but I have no idea what a protochain is.
CSS styles are inherited. This means that when you create a new object and place it as a child of another in the DOM, this new object will have to inherit all the "inheritable" styles from the parent. Then it will override these styles through its stylename or inline styles.
The StyleProtoChain class is responsible for building this style list of any object ( which can have a style ) that is created. It is named thus because this class has to go up the DOMtree ( like going up the prototype chain ... perhaps a misnomer!) and construct the list of styles for this object. The order in which this goes up is specified by this comment.
/**
* #private
* If the styleName property points to a UIComponent, then we search
* for stylable properties in the following order:
*
* 1) Look for inline styles on this object
* 2) Look for inline styles on the styleName object
* 3) Look for class selectors on the styleName object
* 4) Look for type selectors on the styleName object
* 5) Look for type selectors on this object
* 6) Follow the usual search path for the styleName object
*
* If this object doesn't have any type selectors, then the
* search path can be simplified to two steps:
*
* 1) Look for inline styles on this object
* 2) Follow the usual search path for the styleName object
*/
Hope this helps. If anyone wants further reference, you can find a link to the source here
I need to have a place to put some common functions that various view scripts will use such as creating some html by passing it a variable. I know about using helpers, but I want to be able to put many functions inside it not just one helper for each function.
Is it a plugin that I need to create?
thanks
A view helper is definitively the way to go. You can group a collection of similar or related functions using a simple design pattern for your view helper:
class App_View_Helper_Example extends Zend_View_Helper_Abstract
{
/**
* #param mixed|null $var
* #return App_View_Helper_Example
*/
public function example($var = null)
{
if ($var === null) {
return $this;
}
return $this->function1($var); // shortcut to method most used
}
public function function1($var)
{
return $this->view->escape($var);
}
public function function2($var1, $var2)
{
return $this->view->escape(sprintf('%s: %d', $var1, $var2));
}
// and so on...
}
This allows you to call your helper methods in your view like this:
$this->example($var);
$this->example()->function1($var);
$this->example()->function2($var1, $var2);
I used this approach for a Google Static Map helper which provides a centered()-method to display a map centered at a given location and a byMarkers()-method that displays a static map automatically centered and zoomed around a list of given markers.
The only problem you may encounter is keeping a state in your helper across different view scripts (e.g. when using layouts or partials) as the helper will be reconstructed with every single view script. To store state across these boundaries you'll have to resort to Zend_Registry or some static member field.
Hm, 'sounds a bit smelly'. What kind of functions would these be? If your design is ok, you shouldn't have a need for this kind of dustbin class. If it is really all about view then you should create view helpers, view partials or partial loops!
Sounds like what you want is the partial helper
If you don't want to use helpers (including the partial helper) you might as well just create some global functions, stick them in some file, and include it from your bootstrap file.
If you don't want a 'bunch of helpers' (which isnt really all that bad, as other posters have suggested), you can extend Zend_View, add the member methods, then set the Viewrenderer to your extended View.
http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.viewrenderer
Thank you all for the suggestions.
I discovered that you can use a view helper (like Stefan said) to store more functions by just returning $this from it like :
class Zend_View_Helper_FormVars
{
public function formVars(){
return $this;
}
public function openFormFieldGroup($name=''){
$html='';
$html.='<div id="formFldGrpWrapper">';
$html.='<div id="formFldGrpName"><b>'.$name.'</b></div>';
return $html;
}
}
Now in my view script I can use it like this:
$formVars=$this->formVars();
$html.=$formVars->openFormFieldGroup('General');
But I'm also interested in what Justin stated that I can have a common extended view helper?
That all my views or controllers can access for doing repetative tasks like some html divs/styles, etc.... How would I go about getting that set up?
thanks.
But I'm also interested in what Justin stated that I can have a common extended view helper? That all my views or controllers can access for doing repetative tasks like some html divs/styles, etc.... How would I go about getting that set up?
In the answers you ask this additional question. My answer deals with that too.
First you need to ask yourselves why you want to have multiple helper functions in one class
One reason is that you saves you extra classes and file includes. How could you do so?
If they are related you can put them into one view helper. But don't do things like
$this->htmlWrapper()->wrapParapgraph()->wrapContentBox()
->translateFromTo('NL', 'EN');
translateFromTo(…) has nothing to with html-wrapping.
If you want to optimize your includes, you can put you common helper code into a derived View-class:
class MyView extends Zend_View
{
function wrapParagraph() {}
function otherFunction() {}
}
This option is also mentioned in the zend framework guide as a means of optimization.
Please note that view helper reusability isn't affected by the choice to create view helpers as separate classes. You automatically get access to the current view oject if your helper extends Zend_View_Helper_Abstract.
class My_View_Helper extends Zend_View_Helper_Abstract
{
function wrapParagraph($content) {
// do something …
return $this->someOtherViewHelper();
}
}
Further you wrote
$formVars=$this->formVars();
This doesn't make sense actualy, since Zend_View registers only one view helper per view isntance.
$formVars=$this->formVars();
$formVars->doOneThing();
$formVars->doSecondThing();
is equivalent to
$this->formVars()->doOneThing();
$this->formVars()->doSecondThing();
The Singleton aspect has a severe impact on the way you design view helpers as you see.