社会情况下的永久链接

社会情况下的永久链接

本文介绍了如何在codeigniter ....社会情况下的永久链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用codeigniter建立一个网站。网站看起来像我的学校的社会agregator。建立我的网站我计划:

i want to build a website using codeigniter. The website is look like a social agregator for my school. to build my website i plan :


  1. 制作类页面。类pages有一个公共函数登录,

    注册,注销等。

  2. 创建一个user与
    相关的用户需要:编辑个人资料,添加社交API, view_profile 等。

  1. making a class "pages". The class "pages" has a common function login,
    register , logout.. etc.
  2. making a "user" class the class "user" has a function related touser needs like: edit profile, add social api, view_profile etc.



i know if we want to see a profile we should pass an url like :

www.Mysite.com/user/view_profile/ <user name>

我不知道如何制作直接的用户页面我希望我的用户可以访问他的网页只是输入:

I dont know how to make a direct user pages (like permalink). i want my user can access his pages just only to type:

www.Mysite.com/ <user name>

我已经读取了user_guide的代码igniter,但我还是不明白url clas。

i have read the user_guide in code igniter but i still dont understand what the url clas. is there any body can explain me how to make it ?

推荐答案

我会在中设置一个路由, application / config / routes.php 将以用户名作为第一段的任何URL重新映射到您的个人资料视图的控制器方法。

I would set up a route in application/config/routes.php that remaps any URL with a username as the first segment to the controller's method serving your profile view.

实例,在你的routes.php中放置这个代码:

For instance, in your routes.php place this code:

$ route [':any'] =user / view_profile /:any

:any 键将作为变量传递给函数。请记住,默认情况下,路由中的任何东西(任何东西)将被路由到该控制器的方法,所以它可能是一个好主意,让你的永久链接结构看起来像这样: yoursite.com/u /< username> ,在这种情况下,您不需要路由;你可以这样传递uri段:

The :any key will be passed as a variable to the function. Keep in mind that, by default, anything in that route (anything) will be routed to that controller's method, so it might be a good idea to have your permalink structure look like this: yoursite.com/u/<username>, in which case you don't need a route; you can just pass the uri segment like this:

<?php
    class U extends CI_Controller
    {
        function __construct()
        {
            parent::__construct();
            // Load the users model
            $this->load->model('users_model');
        }

        function index()
        {
            // Get the username from the URL
            $username = $this->uri->segment(2);

            // Get the users data from the database using the second URI segment
            $data['user'] = $this->users_model->get_user($username);

            // Load the view
            $this->load->view('path/to/view', $data);
        }
    }

这篇关于如何在codeigniter ....社会情况下的永久链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 05:09