2013-03-30 46 views
2

我有笨传递变量默认的控制器在笨

class Welcome extends CI_Controller { 

    public function index() 
    { 
     $this->load->view('welcome_message'); 
    } 

一个默认的控制器,你知道,我们可以调用这个函数

sitename/index.php 

sitename/ 

我在.htaccess中重写网址

现在我要打电话与参数相同的索引功能通过像

sitename/seo-services 

,其中搜索引擎优化服务将paramater传递给指数函数加载SEO服务页面。

为笨的默认语法

example.com/class/function/ID

我想在这个formet

example.com/class/ID

,我想跳过功能默认(索引)功能类

我该怎么做?

感谢

,你可以看到我试图这样的搜索引擎优化的目的。

回答

4

附加到您网址的参数会自动转换为您方法的参数。

例如,如果您在欢迎控制器有一个方法叫做索引的索引,然后http://www.example.com/index.php/welcome/index/[parametervalue]会自动传递[的parameterValue]你的方法,假设你定义你的函数接收参数

class Welcome extends CI_Controller { 

    public function index($parameterValue=null) 
    { 
     //do whatever you need here 
     //note the default value just in case it is null 
    } 
} 

如果你想使事情变得更短,你将不得不在config/routes.php文件文件中定义的别名。另外,如果你想摆脱index.php,你将不得不相应地配置你的Web服务器(通过.htaccess如果使用Apache或web.config如果使用iis)

+0

亲爱的我做了同样的事,但我得到了错误404页面未找到,实际上我试图将值传递给默认控制器,我的url就像localhost/seo-services – air

+0

正如代码下面的段落所述。你首先需要设置.htaccess(正如文档中提到的http://ellislab.com/codeigniter/user-guide/general/urls.html)。然后,你需要修改你的application/config/routes.php中的路由(正如http://disislab.com/codeigniter/user-guide/general/routing.html中的文档所解释的) –

+0

我想我无法来解释你,看看默认的语法是example.com/class/function/ID我想example.com/class/ID在那里我将跳过类 – air