Welcome Guest, Not a member yet? Register   Sign In
No able to call another function of the loaded controller
#1

[eluser]Jawed[/eluser]
Hi to all,

I am very new to CI.
I created a controller by the name Page2, save it with the file name page2. In this controller I made an index function that called a view and made another function that called other view. the code is as below

class Home extends Controller {

function Home()
{
parent::Controller();
$this->load->helper('url');
$this->load->helper('form');

}
function index()
{

$this->load->view('welcome_message');

}


function page2()
{

$this->load->view('page2');

}

//////////////////////////////////mail////////////////////////////////////////////
}
The view folder has both two files with the names welcome_message.php and page2.
And I put the controller name in the auto load controller. and suppose my site name is abc.com

then when i press enter after abc.com the welcome message page is called. but when I type
abc.com/page2 then enter or abc.com/home/page2/ I got a 404 error. there is no htaccess in my code. I dont know that i am missing. Please help

Thanks in advance
Jawed
#2

[eluser]Dam1an[/eluser]
If you're not using htaccess, you will need to add index.php to the URL
Code:
www.abc.com/index.php/home/page2

Edit: Can you also use [ code ] blocks in the future
#3

[eluser]Jawed[/eluser]
thanks buddy, you are really a life saver. I have an another question. Please help..
This controller was autoloaded. I made another controller by the name Admin

class Admin extends Controller {

function Admin()
{
parent::Controller();
}

function index()
{
$this->load->view('admin');
}
function index_admin()
{
$this->load->view('admin');
}
}

Same site....
then I put the url abc.com/admin/index.php to access the controller..
even i tried abc.com/index.php/admin/
But this is not happening...

please help
Do i have to do something else....
#4

[eluser]Dam1an[/eluser]
What do you mean when you say 'autoload the controller'? As in it's the default?
Of the 2 URLs the first one wouldn't work, as index.php should be the first part of the URL (assuming index.php is in the web root)

I'm not sure why that's not working, I assume you've created the admin view?
Do you get a CI error or normal error?
#5

[eluser]Jawed[/eluser]
I mean that in router file there is an option $route['default_controller'] = "home";. The first the constructor is loaded and the part you suggested in the url is woring. Then i made another controller

class Admin extends Controller {

function Admin()
{
parent::Controller();
}

function index()
{
$this->load->view(‘admin’);
}
function index_admin()
{
$this->load->view(‘admin’);
}
}

Then I wanna ask how to call this controller (Admin ). The files are there in view folder..
abc.com/admin/index.php to access the controller..
even i tried abc.com/index.php/admin/

Thanks in advance
#6

[eluser]Jawed[/eluser]
I got the logic, how this can be done. But I really appreciate ur quick reply and really want to say thank to you. THANKSSSSSS
#7

[eluser]Wuushu[/eluser]
Are you trying to call METHOD1 from withing METHOD2??

IF so, this is how it can be done..
Code:
function index()
{
return $this->page2();
}

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

NM sorry, i think i misunderstood the question.




Theme © iAndrew 2016 - Forum software by © MyBB