首页 \ 问答 \ Yii2 GridView中的HTML(HTML in Yii2 GridView)

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属性设置不同的值,例如rawurlhtml ,但没有成功。 我也没有问题编写自定义函数来返回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 &lt;span class=&#039;test&#039;&gt;HTML&lt;/span&gt;

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 the span 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 as raw, url and html to no success. I also have no problem writing a custom function to return the correct output next to the value 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')]

原文:
更新时间:2022-03-06 07:03

最满意答案

你必须推迟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 until ast 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 move build_ast to an implementation file

Outside of the struct definition:

ast parser::build_ast()
{
    node *ret = new node;
    return ast(ret);
}

To forward-declare node, you need to do this within parser 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 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 ...
  • 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 ...
  • 在第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.
  • 你必须推迟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 ,您需 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。