When I download project in https://www.codeigniter.com/user_guide/installation/downloads.html
CodeIgniter v2.2.0
When I run http://localhost/qldv, I get result as welcome page of codeigniter, but when I register in routes.php with route
$route['admin/welcome'] = 'welcome';
When I go to web with link: http://localhost/qldv/admin/welcome
I don't get welcome page. Result is
Object not found!
Please help me. Thanks
If you don't disable having to put index.php in the URL (using an htaccess file), this route won't work. This would: http://localhost/qldv/index.php/admin/welcome
To disable index.php in the url look at this question:
CodeIgniter removing index.php from url
Put this code in your Welcome Controller.
public function admin()
{
$this->load->view('welcome_message');
}
Put this code in your Welcome Controller.public function admin()
{
$this->load->view('welcome_message');
}
Related
What would be the best way to get uri segment via parameter in controller? i have used following code but not working
uri as
http://localhost/home/23
class Home extends CI_Controller
{
public function index($para){
echo $para;
}
}
Above uri results in 404 page not found error.How to solve such problem and get the id as parameter in index function.
You can write routing in your routes.php file.
File path : application/config/routes.php
$route['home/(:any)'] = 'home/index/$1';
OR
$route['home/index/(:any)'] = 'home/index/$1';
I hope it will help.
I have a really weird problem. I have been using CI for more than 2 years and it's the first time I found this kind of problem. I found that the redirect function is not working properly. I already load the url helper in autoload.php.
$autoload['helper'] = array('url','html','form','file');
What I want to do is to redirect the users to a controller if they call admin controller.
class Admin extends CI_Controller {
function index(){
redirect('secure');
}
}
But what happen is the page redirected to the base_url. I've tried adding the second parameter of redirect with refresh or location but the result is just the same. It also happens to all redirect function in other controller. Can anyone tell me what the cause of this problem to happen?
EDIT:
For additional information that might be helpful for finding the problem, here I put the code of the routes.php.
$route['default_controller'] = "frontpage";
$route['404_override'] = 'errors/page_missing';
$route['admin'] = 'secure';
class Admin extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
function index()
{
redirect('secure', 'refresh');
}
}
I just figured out that the problem is caused by a function in my helper. By coincident, I use site_url() function in the helper, which is already used by the CI. I replace that function with another name and now the redirection is working perfectly. I don't know how it can affects the redirect function, though. Thanks for anybody tried to help me.
I also got this issue in my project and i found some white space at the bottom of my page after closing php tag.
There must be some white space or some kind of echo before your redirect() method or at the bottom of the page.
If this is not the issue then set log threshold to 4 in 'config/config.php' and check 'application/logs' folder.
I had the same problem of redirect function's.
I found the solution by checking it's log file. Which is in \application\logs\
Then find the file which is addressed in log file and check if there is any space or any unused blank lines 'before and after the php tag "" '
If you find any space then remove it. And your redirect function would be work.
Thanks.
it may be the absence of index.php on URL
that is....,
http://localhost/codigniter/index.php/controll_page/function_name
so.,
redirect will be.....!!
redirect(base_url()."index.php/controll_page/function_name");
I have one module that is OfficeModule. In OfficeModule I have two
controller BranchController and BranchTypeController. And two model
BranchModel and BranchTypeModel. And also two view file. Files path
are like that:
protected\modules\office\controllers\branchController.php
protected\modules\office\controllers\branchtypeController.php
protected\modules\office\models\Branch.php
protected\modules\office\models\BranchType.php
I have one Module file: protected\modules\office\OfficeModule.php
When I call from url
projectname.test.com/office/branch I want to redirect like that:
projectname.test.com/office/branchtype. Now I am writing redirect() in
OfficeModule.php within
public function beforeControllerAction($controller, $action){
$controller->redirect(array('../branchtype'));
}
But it doesn't work and can't redirect. Anyone please help me. Thanks a lot!
That's ok like that: :)
public function beforeControllerAction($controller, $action)
{
$getcontroller = Yii::app()->controller->id;
if($getcontroller == 'branch'){
$controller->redirect(array('/office/branchtype'));
}
}
Try:
$controller->redirect(array('branchtype/index'));
it's redirects to your module's controller branchtype and action index. And
$controller->redirect(array('/branchtype/index'));
redirects to the app controller branchtype and action index (outside the module)
I'm trying to add a view just a simple contact page, I already have other views.
Here's what I've done so far:
added 'contact' in my routes file here
$route['^(?!/|site|ajax|gallery|contact).*'] = "site/view/$1";
added contact.php to my application/views folder
added contact() to my site controller (whole controller here http://pastebin.com/CCjjrV8R)
function contact() {
$this->load->model('Site_model');
$this->load->view('contact');
}
When I visit the correct url for the view (domain.com/contact), I get a page with partial content and "404" in the
Can anyone see a problem? This is very puzzling.
I don’t think you need the view part of the URL in the route?
A newbie here: sorry if the question is too simple, been looking in tutorials but I don't seem to look properly.
I have the
$route['default_controller'] = "mainpage";
in routes.php working properly, and now I just want to view one of the php pages in views folder by typing its url:
http://myserver/folder/thepageIwantToSee
I get a 404 Not Found error. Do I have to use a controller? I just want to see it first before any linking, is there a way to do it?
Thanks a lot!
class yourcontroller extends CI_Controller {
function pageiwanttosee()
{
code
code
$this->load->view('the_view_page', $data);
}
}
Yes, you can write a controller that displays the view specified.
http://myserver/showfile/folder/thepageIwantToSee , where showfile is your controller.
Don't forget to set some security check or disable this on production site.