我应该怎么写才能从CI中的Controller重定向页面? [英] what should i write to redirect the page from Controller in CI?

查看:65
本文介绍了我应该怎么写才能从CI中的Controller重定向页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的控制器

<?php 
class First_Controller extends CI_Controller{
    public function index(){

        $this->load->view('firstpage');
    }

    public function validate_credentials()
    {
        $data[] =array(

            $username=$this->input->post('username'),
            $password=$this->input->post('password')
            );
        $this->load->model('First_Model');
        $result=$this->First_Model->validate($data);

        if($result==true)
        {
            //redirect('welcome');//Error Page is not found
            echo "found";
        }
        else{

            echo "not found";
        }
    }

}
?>

and here is the second controller 



   <?php 
    class Welcome_Controller extends CI_Controller{
        public function index(){

            $this->load->model('First_Model');
            $data['results']=$this->First_Model->display();

            $this->load->view('welcome',$data);
    }       }   
    ?>

如果我向页面间接写入,则会显示找不到错误页面,如果我给它一个控制器相同的错误,如果我给页面重定向('欢迎');显示错误。我不知道该怎么办,谁能指导我。谢谢

if i write indirect to my page it show the error page is not found , if i give it a controller same error , and if i gave page redirect('welcome'); show error . i dont know what to do , could anyone guide me . thanks

推荐答案

按照以下步骤操作:


  1. 您加载了 URL助手吗?

如果没有,则先加载url辅助程序

if not then first load the url helper

$ this->加载-> helper('url');

在您的功能构造函数中>。

如果要在整个应用程序中使用它,则将其加载到 autoload.php 文件

if you want to use it in whole application then load it in autoload.php file

在您的 config.php 文件中,提供您的网站网址

In your config.php file give your site url

$ config ['base_url'] ='您的网站网址';

重定向函数使用 url辅助函数

redirect(base_url()。'welcome' );

如果您要重定向到另一个控制器的函数,请像

if you want to redirect on another controller's function pass it like

redirect('Welcome_Controller');

如果该函数是索引,则无需对其进行定义,即可对其进行重定向另一个函数

if the function is index no need to define it, to redirect on another function

redirect('Welcome_controller / anotherFuncti );

这篇关于我应该怎么写才能从CI中的Controller重定向页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆