CodeIgniter Anchor error: URL not found on this server

前端 未结 1 834
情书的邮戳
情书的邮戳 2021-01-21 14:26

I have been for hours to make a simple anchor link working without success.

My controller is

class Welcome extend         


        
相关标签:
1条回答
  • 2021-01-21 14:45

    The base_url config MUST contains the protocol and a trailing slash as well.

    From the config.php file:

    URL to your CodeIgniter root. Typically this will be your base URL,
    WITH a trailing slash:

    http://example.com/
    

    If this is not set then CodeIgniter will guess the protocol, domain
    and path to your installation.

    Hence, you could set the base_url as follows, or in this case simply leave it blank:

    $config['base_url'] = 'http://localhost/';
    
    # base_url should be absolute, If you've installed CI in sub-folder:
    $config['base_url'] = 'http://localhost/path/to/codeigniter_folder/';
    

    Side-note: in order to use URL helper functions such as anchor(), load the helper file at first: $this->load->helper('url'); (or load the helper automatically via autoload.php config file).


    Why does base_url config affect anchor() function?

    anchor() function, uses site_url() helper function to determine the URL address of the hyperlink.

    And the site_url() itself, uses two base_url and index_page configs to create the URL address.

    Hence if you assign a wrong value to base_url and/or index_page configs, the anchor() function won't work properly.

    0 讨论(0)
提交回复
热议问题