How do I get the project basepath in CodeIgniter

前端 未结 6 723
失恋的感觉
失恋的感觉 2020-12-15 03:22

I have created a folder as user in the root directory.

My project base path is:

/var/www/myproject/

When I want to access the base

6条回答
  •  Happy的楠姐
    2020-12-15 03:38

    Obviously you mean the baseurl. If so:

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

    Root in codeigniter specifically means that the position where you can append your controller to your url.

    For example, if the root is localhost/ci_installation/index.php/, then to access the mycont controller you should go to localhost/ci_installation/index.php/mycont.

    So, instead of writing such a long link you can (after loading "url" helper) , replace the term localhost/ci_installation/index.php/ by base_url() and this function will return the same string url.

    NOTE: if you hadn't appended index.php/ to your base_url in your config.php, then if you use base_url(), it will return something like that localhost/ci_installation/mycont. And that will not work, because you have to access your controllers from index.php, instead of that you can place a .htaccess file to your codeigniter installation position. Cope that the below code to it:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /imguplod/index.php/$1 [L]
    

    And it should work :)

提交回复
热议问题