如何使用href链接转到codeigniter中的另一个页面

时间:2017-09-20 08:58:35

标签: php codeigniter

我的项目中有一个名为Welcome的控制器,它有两个函数,一个是index(),它加载一个名为interior的主页,另一个函数是architect(),用于加载架构师页面。

<a class="catname activecat" href= "<?php echo base_url(''); ?>">Interior</a> 

       <a class="catname" href="<?php echo site_url('welcome/architect'); ?>">Architect</a>

这个问题很受欢迎/架构师没有工作,也没有去建筑师页面。

我的欢迎控制器具有以下代码:

public function index()
    {   
        $this->load->model("Interior_listing_model","interior");
        $articles = $this->interior->interior_list();

        // Load Interior Listing View
        $this->load->view("interior/interior",["articles"=>$articles]);
    }

    public function architect()
    {   
        $this->load->helper('url');
        $this->load->model("Interior_listing_model","interior");
        $articles = $this->interior->architect_list();

        // Load Interior Listing View
        $this->load->view("architect/architect",["articles"=>$articles]);
    }

3 个答案:

答案 0 :(得分:1)

Change like this..

<a class="catname" href="<?php echo base_url();?>/welcome/architect">Architect</a>

base和site url之间的差异:

echo base_url(); // http://example.com/website
echo site_url(); // http://example.com/website/index.php

我认为你的htaccess是个问题

Steps To Remove index.php using .htaccess:-

Step:-1  Open the file config.php located in application/config path.  Find and Replace the below code in config.php  file.

//  Find the below code

$config['index_page'] = "index.php"

//  Remove index.php

$config['index_page'] = ""
Step:-2  Go to your CodeIgniter folder and create .htaccess  file.


 Path:

Your_website_folder/
application/
assets/
system/
user_guide/
.htaccess <--------- this file
index.php
license.txt
Step:-3  Write below code in .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Step:-4  In some cases the default setting for uri_protocol does not work properly. To solve this issue just open the file config.php located in application/config and then find and replace the code as:

//  Find the below code

$config['uri_protocol'] = "AUTO"

//  Replace it as

$config['uri_protocol'] = "REQUEST_URI" 

答案 1 :(得分:0)

config.php$config['base_url'] = '127.0.0.0/newbluemasons/';中 在routes.php$route['default_controller'] = 'welcome';中 试试这个,我已经做了一些实验..

<a href="<?php echo base_url().'/' ?>">Interior</a>
<a href="<?php echo base_url().'index.php/architect' ?>">Architect</a>

答案 2 :(得分:0)

试试这个,

的.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

HTML:

<a href="<?php echo site_url('about-us'); ?>" 

配置/ Routs.php

$route['about-us'] = "welcome/aboutus";

控制器功能

public function aboutus()
{
    $this->load->view('about');
}

创建about.php

希望这会对你有帮助!