【问题标题】:base_url() and site_url() not working in live server [closed]base_url()和site_url()在实时服务器中不起作用[关闭]
【发布时间】:2015-07-16 03:54:13
【问题描述】:

我正在研究 codeigniter。我试图在表单操作中调用控制器函数。

<form action="<?php echo site_url("Welcome/InsertValue");?>" method="post" name="frm1"  >

这在本地服务器上完美运行。但在实时服务器中显示404 Page Not Found 错误。

这是我的控制器功能

function InsertValue(){

        $this->load->database();

            /*db(Insert)*/
        $this->load->model("get_db");

        $data = array(
        'p_name' => $this->input->post('pname'),
        'y_addr' => $this->input->post('addr'),
        'rating' => $this->input->post('rating'),
        'apartment' => $this->input->post('apartment'),
        'web_url' => $this->input->post('website'),
        'p_manage_qu' => $this->input->post('pcompany'),
        'country' => $this->input->post('country'), 
        'city' => $this->input->post('city'),
        'p_addr' => $this->input->post('paddr'),
        'zip' => $this->input->post('zip'),
        'contact' => $this->input->post('contact')
    );

        $this->get_db->insert1($data);
        /*echo "new row added";*/
        /*db(Insert)*/

        $this->load->helper('url');
        $this->load->view('supplier/property');
    }

【问题讨论】:

  • 请检查'Welcome/InsertValue'的大小写(小写/大写)。
  • 试试site_url("welcome/insertvalue")
  • $this->load->helper('url'); - 确保这已经完成
  • 您在显示 404 错误的 url 获得的链接
  • @ShaifulIslam 显示 404 Page Not Found 错误

标签: php codeigniter


【解决方案1】:

由于控制器名称、路径等的原因,在 localhost 上运行而不在实时 Linux 主机上运行的事情是 99%。

当您在 Windows 或 MAC 上进行开发时,它们并不关心大小写。 Linux 可以。

因此,如果您的 Live Host 是基于 linux 的... 您的欢迎控制器在 URL 中应该是小写的。

顺便说一句:命名方法通常使用小写字母,即insert_value 或驼峰式insertValue。但这不应该成为阻碍——它更像是一种编码风格的约定。 CI 建议使用下划线来分隔小写字母,即 insert_value。

<?php echo base_url();?>index.php/welcome/InsertValue

您在 URL 中的 Welcome Controller 名称为 welcome(全部小写)和 NOT Welcome

另外,请始终查看页面源中生成的链接等,以确保它看起来不错!从您的浏览器。这通常是鼠标右键单击 - 查看源代码(取决于您使用的浏览器)。或者您可以 F11 并在面板中查看源代码或右键单击检查元素...您需要知道如何查看正在生成的内容并在遇到问题时尝试一下。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-10
    • 2016-06-23
    相关资源
    最近更新 更多