gpt4 book ai didi

yii - 为什么我们在操作管理中使用 $model = new ModelName ('search' )?

转载 作者:行者123 更新时间:2023-12-02 08:44:50 25 4
gpt4 key购买 nike

即使我们正常创建对象它在操作管理中工作,那么为什么我们在创建对象时使用搜索参数?

我不明白在创建 modelobject 时发送 id 以及搜索的以下代码的用法

$model=new ModelName('search&id='.$_GET['id']);

最佳答案

该参数表示模型场景,它告诉模型在需要场景(如验证)的任何地方使用哪个场景。这里的文档说:

__construct() method public void __construct(string $scenario='insert') $scenario string scenario name. See CModel::scenario for more details about this parameter.

以及有关CModel::scenario 文档的文档:

scenario property public string getScenario() public void setScenario(string $value)

Returns the scenario that this model is used in.

Scenario affects how validation is performed and which attributes can be massively assigned.

A validation rule will be performed when calling validate() if its 'on' option is not set or contains the current scenario value.

And an attribute can be massively assigned if it is associated with a validation rule for the current scenario. Note that an exception is the unsafe validator which marks the associated attributes as unsafe and not allowed to be massively assigned.

简单的说就是新建模型,告诉它我们在搜索场景。

关于yii - 为什么我们在操作管理中使用 $model = new ModelName ('search' )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13245928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com