简体   繁体   English

从控制器重定向到Codeigniter主页

[英]Redirect to Codeigniter homepage from a controller

My default controller is Welcome.php and the index.php file (Home page) shows on the URL localhost://mysite/index.php 我的默认控制器是Welcome.php,index.php文件(主页)显示在URL localhost://mysite/index.php上

When a user go through some process say he comes to the URL localhost://mysite/index.php/FirstController/func 当用户经过某个过程时,说他进入URL localhost://mysite/index.php/FirstController/func

Here I want to send the user to the home page if post data or session data is not available. 如果发布数据或会话数据不可用,我想在这里将用户发送到主页。 (ie if user directly insert the above URL without going through the process). (即,如果用户直接插入上面的URL而没有经过该过程)。 For that I used 为此,我用了

$this->load->view('index.php');

inside the "func" function in "FirstController" controller. 在“ FirstController”控制器的“ func”函数中。 But when i do so, my Home page isn't properly displaying because now all the css, js, image files I'm importing will get called in localhost://mysite/index.php/FirstController/func URL, but not in 但是,当我这样做时,我的主页无法正确显示,因为现在我要导入的所有CSS,JS,图像文件都将在localhost://mysite/index.php/FirstController/func URL中调用,但不会在

localhost://mysite/index.php URL so that each such imported file has to go two more steps backwards to find the correct path. localhost://mysite/index.php URL,以便每个这样的导入文件都必须向后再走两步才能找到正确的路径。

(Say I'm importing mysite/assets/img/photo1.jpg to my home page, now it's trying to load mysite/FirstController/func/assets/img/photo1.jpg so it gives a 404 error) (假设我将mysite / assets / img / photo1.jpg导入到我的主页,现在它正尝试加载mysite / FirstController / func / assets / img / photo1.jpg,这样会出现404错误)

So my question is , is there a way to call my Home function from the localhost://mysite/index.php URL directly or to load Home file inside the "func" function in "FirstController" controller without disturbing its imported file paths. 因此,我的问题是,是否有一种方法可以直接从localhost://mysite/index.php URL调用我的Home函数,或者在不干扰其导入文件路径的情况下在“ FirstController”控制器的“ func”函数中加载Home文件。

Thanks in advance. 提前致谢。

Follow this path: First set base path : 遵循以下路径:首先设置基本路径:

Application>config>config.php
$config['base_url'] = 'localhost://mysite/';

Second set default controller: 第二组默认控制器:

Application>config>routes.php

set your index or home page controller 设置索引或主页控制器

$route['default_controller'] = 'home';

Third: load the view in the default controller 第三:在默认控制器中加载视图

$this->load->view('index.php');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM