Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我在Codeigniter中创建了一个自定义url,但post数据可以';不显示_Php_Codeigniter_Url Rewriting_Url Routing - Fatal编程技术网

Php 我在Codeigniter中创建了一个自定义url,但post数据可以';不显示

Php 我在Codeigniter中创建了一个自定义url,但post数据可以';不显示,php,codeigniter,url-rewriting,url-routing,Php,Codeigniter,Url Rewriting,Url Routing,我创建了一个网上购物商店与供应商系统,我希望每个供应商的个人资料显示与他的用户名在url。 显示我的当前url,id号如下 www.mydomain.com/home/profile/1 我希望我的url在url中显示用户名,如: www.mydomain.com/username 我的代码在这里: 型号 //get all vendors public function vendor_profiles() { $where = array('ven_st

我创建了一个网上购物商店与供应商系统,我希望每个供应商的个人资料显示与他的用户名在url。 显示我的当前url,id号如下

www.mydomain.com/home/profile/1  
我希望我的url在url中显示用户名,如:

www.mydomain.com/username
我的代码在这里:

型号

    //get all vendors
public function vendor_profiles()
    {
        $where = array('ven_status' => 'Active');
        $this->db->select()
                 ->from('vendor_login')
                 ->where($where,'DESC');
        $data = $this->db->get();
        return $data->result_array();
    }

         //get single vendor through id number
    public function vendor_profile($id)
    {
        $where = array(
            'vendor_id' => $id,
            'ven_status' => 'Active',
        );
        $this->db->select()
                 ->from('vendor_login')
                 ->where($where,'DESC');
        $data = $this->db->get();
        return $data->first_row('array');
    }
控制器

//show all vendors profile
public function vendor_profiles()
    {
        $data['profiles'] = $this->front->vendor_profiles();
        $this->load->view('vendors',$data);
    }

        //show single vendor profile through id
    public function profile($id)
    {
        $data['profile'] = $this->front->vendor_profile($id);
        $this->load->view('profile',$data);
    }
视图:

//here is show all vendor profiles (vendors.php)

<?php foreach($profiles as $vendor) : ?>

<a href="<?=base_url();?>home/profile/<?=$vendor['vendor_id'];?>"><img src="<?=base_url();?>uploads/<?=$vendor['ven_img'];?>"></a>

<a href="<?=base_url();?>home/profile/<?=$vendor['vendor_id'];?>"><?=$vendor['ven_firstname'];?></a>

<?php endforeach; ?>



           //Here is single vendor profile show (profile.php)

<p><img src="<?=base_url();?>uploads/<?=$profile['ven_logo'];?>"></p>
<p><img src="<?=base_url();?>uploads/<?=$profile['ven_img'];?>"></p>
<p>First Name : <?=$profile['ven_firstname'];?></p>
<p>Last Name : <?=$profile['ven_lastname'];?></p>
<p>Username : <?=$profile['username'];?></p>
require_once( BASEPATH .'database/DB.php');
$db =& DB();
$query = $db->get('vendor_login');
$result = $query->result();
foreach ($result as $row) {
    $rout["home/profile/" . $row->username] = "home/profile/" . $row->vendor_id;
}
建议: 尽量避免创建像这样的配置文件URL

www.mydomain.com/username
如果有人在应用程序中创建与现有页面相同的用户名,则可能会导致问题

例如,假设您有一个类似
www.mydomain.com/shop
的URL,其中显示您的店铺首页。如果有人创建用户名商店,它将无法工作

如果用户名字段是唯一的,则不需要以这种方式创建路由。相反,你可以使用

$route['profile/(:any)']="home/profile/$1";
有了它,您可以创建一个有意义的配置文件URL,比如

www.mydomain.com/profile/username
现在在controller Home.php中更改
profile
方法,如下所示

public function profile($username)
{
// call your model function to retrieve userprofile with the unique username
// the username will be on $username variable
}
您的配置文件URL可按如下方式生成:

<a href='<?php echo base_url('profile/$username');?>'><?php echo $username;?></a>

$rout还是$route?请先检查一下,然后告诉我们输出结果。你可以考虑阅读CI教程关于这里的路由: