Reputation: 3667
Excuse me if this is slightly newbie.
I have the main view located @ app/views/index.php as:
<?php echo $head ?>
</head>
<body>
<div id="container">
<h1>Welcome to CodeIgniter!</h1>
<div id="body">
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>
<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>
<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/welcome.php</code>
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>
</body>
</html>
The header_meta.php file located at (app/views):
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<link rel="icon" type="image/png" href="img/favicon.ico" />
<!--meta-->
the controller, named SpecialPage.php located at app/controllers/:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class SpecialPage extends CI_Controller {
function SpecialPage(){
parent::CI_Controller();
}
public function index()
{
$head = $this->load->view('header_meta', '', true);
$this->load->view('index', array('head' => $head));
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
Error I'm getting on SpecialPage.php controller:
Call to undefined method CI_Controller::CI_Controller() on line 6
which is:
function SpecialPage(){
parent::CI_Controller();
}
Why is this still just showing a 404 error?????
Upvotes: 1
Views: 1135
Reputation: 666
Try to add this code to your controller maybe you miss this
function SpecialPage(){
parent::CI_Controller();
}
Note : Make sure that your controller name is the same with the file name
And I have another question bro,How you call the page to load?
Gudluck!!
Upvotes: 0
Reputation: 1
The function SpecialPage()
should be __construct()
and parent::CI_Controller()
should be parent::__construct();.
Good luck
Upvotes: 0
Reputation: 6499
Your page should be named as:
specialPage.php
instead of index.php under your controller folder.
Read here for more about controller naming conventions.
This is either expected to use like yourhost.com/index.php/specialPage
or yourhost.com/specialPage
(if your .htaccess
rewrite is enabled).
Codeigniter tries to open a file depending upon what classname
(via controller/model
) you specify. Codenigniter has no idea why it should load index.php
for your class files (unless you specify your classname as Index
).
And I personally recommend not to use index.php for your files as it may confuse you and others, that this would be a self-loading file. Whereas, in codeigniter, the only self-loading file is index.php
in the root folder of your codeigniter installation. And all other files are loaded through index.php (and files that it further includes) only.
Upvotes: 1
Reputation: 1994
I suppose it's this line:
<?php $this->load->view('header_meta.php'); ?>
The ".php" extension seems to be the culprit.
BTW, I do not recommend using PHP code in your views (except echoes and loops). Much better is to compose it in your controller:
$head = $this->load->view('header_meta', '', true);
$this->load->view('index', array('head' => $head));
Obviously, the "$t>l>v()" must be changed to "echo $head". Or, the way I prefer (using a template view):
$body = $this->load->view('index', '', true);
$this->load->view('template', array('body' => $body));
Upvotes: 2