How do I get the project basepath in CodeIgniter

前端 未结 6 722
失恋的感觉
失恋的感觉 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条回答
  • 2020-12-15 03:29

    use base_url()

    echo $baseurl=base_url();
    

    if you need to pass url to a function then use site_url()

     echo site_url('controller/function');
    

    if you need the root path then FCPATH..

    echo FCPATH;
    
    0 讨论(0)
  • 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 :)

    0 讨论(0)
  • 2020-12-15 03:42

    Following are the build-in constants you can use as per your requirements for getting the paths in Codeigniter:

    EXT: The PHP file extension
    
    FCPATH: Path to the front controller (this file) (root of CI)
    
    SELF: The name of THIS file (index.php)
    
    BASEPATH: Path to the system folder
    
    APPPATH: The path to the “application” folder
    

    Thanks.

    0 讨论(0)
  • 2020-12-15 03:46

    Change your default controller which is in config file.

    i.e : config/routes.php

    $route['default_controller'] = "Your controller name";
    

    Hope this will help.

    0 讨论(0)
  • 2020-12-15 03:54

    Use FCPATH instead of BASEPATH for more check this link.

    Codeigniter - dynamically getting relative/absolute path outside of application folder

    0 讨论(0)
  • 2020-12-15 03:56

    Codeigniter has a function that retrieves your base path which is:

    FCPATH and BASEPATH i recommand use FCPATH.
    

    for your base url use:

    <?=base_url()?>
    

    if your php short tag is off

    <?php echo base_url(); ?>
    

    for example: if you want to link you css files which is in your base path

    <script src='<?=base_url()?>js/jquery.js' type='text/javascript' />
    
    0 讨论(0)
提交回复
热议问题