Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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
Php 如何在codeigniter中使用站点\u url_Php_Html_Wordpress_Codeigniter - Fatal编程技术网

Php 如何在codeigniter中使用站点\u url

Php 如何在codeigniter中使用站点\u url,php,html,wordpress,codeigniter,Php,Html,Wordpress,Codeigniter,我面临着这个问题。当我试图在视图中访问test_product/import.php时,我会遇到这个问题 遇到错误。您请求的操作不正确 允许 myimport.php位于/view/test\u product/import.php中。我通过/view/test\u product/all.php中的all.php打开它 下面是我为all.php编写的代码 <form id="submit_form" action="<?php echo site_url("Test_product

我面临着这个问题。当我试图在视图中访问test_product/import.php时,我会遇到这个问题

遇到错误。您请求的操作不正确 允许

myimport.php位于/view/test\u product/import.php中。我通过/view/test\u product/all.php中的all.php打开它

下面是我为all.php编写的代码

<form id="submit_form" action="<?php echo site_url("Test_product/import");?>" method="post">
<p align="right"><button name="import" type="submit" class="btn btn-primary" id="submiting" data-loading-text="Adding ... <span class='fa fa-fw fa-spinner'></span>" form="submit_form">Import </button></p>

您正在双引号内使用双引号。

试试


如果未加载url\u帮助程序,请尝试
如果要自动加载URL

file location :application/config/autoload.php
$autoload['helper'] = array('url');
如果要根据需要加载:

建议
最好自动加载url\u助手,因为我们在任何地方都需要它。 如果要访问css、js、图像等资源,请使用
base\u url()
,否则,
site\u url()

此错误与“site\u url”无关。这与Codeigniter CSRF保护有关。 要解决此问题,您应该:

  • 使用form_open()和form_close()帮助函数,而不是使用普通HTML来创建表单。使用辅助功能时,“csrf令牌”将自动作为隐藏字段插入表单中

  • 如果不能使用form_open()或form_close(),则可以使用

    $this->security->get_csrf_hash()

    $this->security->get_csrf_token_name()

    并通过在表单中添加令牌作为隐藏输入字段手动发送它们


    既然您说import.php在视图中,那么它就被归类为视图文件。您不能直接从站点url访问视图文件。您需要创建一个控制器,以便能够访问视图

    application > controllers > test_product > Import.php 
    
    Import.php的控制器

    <?php
    
    class Import extends CI_Controller {
    
    public function index() {
       // Form submit info goes here.
       $this->load->view('import_view');
    }
    
    }
    

    您应该在控制器构造方法或调用视图的函数中加载url\u helper,如$this->load->helper('url')。阅读此内容我尝试调用它,但仍然出现相同的错误。我尝试将其放入控制器类中,但不起作用我更改答案,检查它的相同问题。遇到错误。您请求的操作不允许。您是否从站点_url()内部删除了双引号?是的,这是编辑后的“我的代码”
    
    <?php
    
    class Import extends CI_Controller {
    
    public function index() {
       // Form submit info goes here.
       $this->load->view('import_view');
    }
    
    }
    
    <form action="<?php echo base_url("test_product/import");?>"  method="post">