Yii2 GridView中的HTML(HTML in Yii2 GridView)
我试图在位于Yii2 GridView中的列中显示一些HTML编码的字符串作为纯HTML。 来自数据库的字符串如下所示:
Testing <span class='test'>HTML</span>
如果我只是使用HTML解码
Html::decode($theStringAbove);
显示它Html::decode($theStringAbove);
然后我在专栏中得到这个:Testing <span class='test'>HTML</span>
但是,我的目标只是获取
Testing HTML
并在代码中围绕HTML单词使用span
标记,但不显示为字符串。我已经尝试为
format
属性设置不同的值,例如raw
,url
和html
,但没有成功。 我也没有问题编写自定义函数来返回value
属性旁边的正确输出,这只是我无法弄清楚如何获得我需要的输出。 欢迎任何建议,谢谢!编辑:这是一个小代码片段,如果这有用:
[ 'format' => 'raw', 'value' => function($model) { return Html::decode($model->text); }, 'label' => Yii::t('app', 'Some Label')]
I'm trying to display some HTML encoded strings as pure HTML in a column positioned in Yii2 GridView. The string that comes from the database looks like this:
Testing <span class='test'>HTML</span>
If I just display it using HTML decode
Html::decode($theStringAbove);
then I get this in the column:Testing <span class='test'>HTML</span>
However, what I'm aiming at is simply getting
Testing HTML
and having thespan
tag around the HTML word in the code but not displayed as a string.I've tried setting different values to the
format
attribute such asraw
,url
andhtml
to no success. I also have no problem writing a custom function to return the correct output next to thevalue
attribute, it's just that I can't figure out how to get to the output I need. Any suggestions are welcome, thank you!EDIT: Here's a small code snippet if that's helpful:
[ 'format' => 'raw', 'value' => function($model) { return Html::decode($model->text); }, 'label' => Yii::t('app', 'Some Label')]
原文:
最满意答案
你必须推迟
build_ast
的定义,直到ast
是一个完整的类型:inline ast build_ast(); //here we want to use object of ast type
inline
在这里使这个声明在功能上与你在例子中所做的一致。 您可能希望将其删除并将build_ast
移动到实现文件在结构定义之外:
ast parser::build_ast() { node *ret = new node; return ast(ret); }
要转发声明
node
,您需要在parser
定义中执行此操作。 换句话说,你不能在没有定义外层的情况下转发声明一个内部类。struct parser { struct node; // ... };
然后您可以继续定义:
struct parser::node { node *parent; };
You have to defer the definition of
build_ast
untilast
is a complete type:inline ast build_ast(); //here we want to use object of ast type
inline
is here to make this declaration functionally identical to what you had in example. You may want to remove it and movebuild_ast
to an implementation fileOutside of the struct definition:
ast parser::build_ast() { node *ret = new node; return ast(ret); }
To forward-declare
node
, you need to do this withinparser
definition. In other words, you cannot forward-declare an inner class without defining the outer.struct parser { struct node; // ... };
You can then proceed with a definition:
struct parser::node { node *parent; };
相关问答
更多-
结构声明(struct declaration)[2023-09-08]
第一个只定义struct x类型。 第二个定义了struct _x类型, 并定义了一个名为x类型的变量。 虽然它可能不是你想到的,但是以_x这样的下划线开头的名称是在文件范围内保留的,所以除非这是在其他范围内,否则第二个具有未定义的行为。 The first defines only the type struct x. The second defines the type struct _x and defines a variable of that type named x. Though it's ... -
这就是所谓的“比特场” 。 它用于内存优化。 它允许您以比您需要的更少的空间存储类型。 (来自上述链接的代码)。 #include
#include struct { unsigned int age : 3; } Age; int main( ) { Age.age = 4; printf( "Sizeof( Age ) : %d\n", sizeof(Age) ); printf( "Age.age : %d\n", Age.age ) ... -
你正在分配一个数组。 你仍然需要分配它的每个元素。 如果你想在.c文件中隐藏结构,那么封装它的创建也是一个好主意。 因此,您的struct的用户不会烦恼是否使用sizeof(member_t)或sizeof(*member_t)或sizeof(struct MEMBER_T) 。 除了typedef struct MEMBER_T* member_t之外,在你的标题中定义一个函数membet_t* create_member_array(int) 。 在你的.c文件中实现它 member_t* create ...
-
结构DIR的前向声明(forward declaration of struct DIR)[2022-08-12]
curr_dir->d_name应该是curr_dir->d_name elem->d_name 。 正如错误所说的,你错误地试图将指针取消引用到不透明类型DIR 。 curr_dir->d_name should be elem->d_name. As the error says, you're incorrectly trying to dereference a pointer to the opaque type DIR. -
规范在3.3.2p6bullet2中说明了这一点(它实际上只是说明了声明名称所添加的范围。如果我没记错的话,没有明确的规则说该类是该命名空间的成员)。 我认为这是一个重要的C兼容性功能。 如果不是这样,那么类在C中是全局的,而在C ++中是类成员。 The spec says this in 3.3.2p6bullet2 (it actually just says into what scope the name declared is added to. If I remember correctly, ...
-
根据Oli Charlesworth的评论,这应该可行。 一般情况下,您可能希望: 将CardState放入其自己的标头中,然后在所有“客户端”标头中#include它,从而避免因这些标头的包含顺序而引起的任何复杂情况。 将Session::cardState_声明为(智能)指针,避免需要实际的CardState声明。 - 编辑--- 既然您已经编辑了代码,那么很明显存在循环包含依赖关系,在这种情况下,您的代码确实不起作用,因此您必须应用上述解决方案之一。 As per Oli Charlesworth's ...
-
错误:结构的前向声明(error: forward declaration of struct)[2022-03-08]
在第36行的Proprietario.cpp中,您可以使用Motocicleta类进行一些操作,而不必先包含完整的类声明(您只有前向声明)。 In Proprietario.cpp on line 36 you do something with class Motocicleta, without including full class declaration first (you only have a forward declaration). -
需要使用以下命令删除GLUquadricObj : gluDeleteQuadric(GLUquadricObj *); GLUquadricObj needs to be deleted using: gluDeleteQuadric(GLUquadricObj *);
-
不,它无法完成。 要访问A的成员,无论成员是类型,数据还是函数,都必须定义它。 No, it cannot be done. To access the members of A it has to be defined, regardless of whether the member is a type, data or function.
-
成员结构的前向声明(Forward declaration of member struct)[2022-11-28]
你必须推迟build_ast的定义,直到ast是一个完整的类型: inline ast build_ast(); //here we want to use object of ast type inline在这里使这个声明在功能上与你在例子中所做的一致。 您可能希望将其删除并将build_ast移动到实现文件 在结构定义之外: ast parser::build_ast() { node *ret = new node; return ast(ret); } 要转发声明node ,您需 ...