Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP3.6:注意(8):未定义索引:搜索,但所需功能正常_Php_Search_Cakephp - Fatal编程技术网

CakePHP3.6:注意(8):未定义索引:搜索,但所需功能正常

CakePHP3.6:注意(8):未定义索引:搜索,但所需功能正常,php,search,cakephp,Php,Search,Cakephp,我正在实现如下搜索功能: index.ctp <div class="Search"> <?php // The base url is the url where we'll pass the filter parameters $base_url = array('controller' => 'ExpiringServices', 'action' => 'index'); echo $this-

我正在实现如下搜索功能:

index.ctp

<div class="Search">
        <?php
        // The base url is the url where we'll pass the filter parameters
        $base_url = array('controller' => 'ExpiringServices', 'action' => 'index');
        echo $this->Form->create("Filter",array('url' => $base_url, 'class' => 'filter'));
        // Add a basic search 
        echo $this->Form->input("search", array('label' => false, 'placeholder' => "Name or surname..."));

        echo $this->Form->submit("Refresh");

        echo $this->Form->end();
        ?>
</div>
但当搜索按预期工作时,我收到以下错误:

注意(8):未定义索引:搜索[APP/Controller\ExpiringServicesController.php,第27行]

如果我使用
debug($searchInput)
我可以看到它包含搜索输入文本。但是如果我使用
if(isset($\u FILES[$this->request->data['search']])
它不会进入if语句内部,就像它没有设置一样

如何解决此问题?

您应该改用:

这将防止未定义的索引错误,直接从文档:

任何不存在的键都将返回
null

$foo = $this->request->getData('Value.that.does.not.exist');
// $foo == null
您应改为使用:

这将防止未定义的索引错误,直接从文档:

任何不存在的键都将返回
null

$foo = $this->request->getData('Value.that.does.not.exist');
// $foo == null
if(isset($\u文件[$this->request->data['search']])
来自哪里?美元文件部分?这只包含上传的文件,如果你没有任何文件(尤其是搜索词名称),那么当然不会设置它?正如FrankerZ所说,使用getData来阻止这些通知。如果(isset($\u文件[$this->request->data['search']])来自哪里?美元文件部分?这只包含上传的文件,如果你没有任何文件(尤其是搜索词名称),那么当然不会设置它?正如FrankerZ所说,使用getData来防止这些通知。
$foo = $this->request->getData('Value.that.does.not.exist');
// $foo == null