The CodeIgniter has a very simple default error 404 message:
404 Page Not Found
The page you requested was not found.
Instead of using this error message on totally blank page, I want to wrap this message in between my header and footer view, so that the error message have similar look to the other pages.
For that purpose, I have created an error view? For example:
my404_view.php
<? $this->load->view('header'); ?>
404 Page Not Found
The page you requested was not found.
<? $this->load->view('footer'); ?>
Now, How can I use this my404_view.php as a default view to display 404 messages instead of using the CodeIgniter default error message.
You should change your routes.php. For example:
in application/config/routes.php
$route['404_override'] = 'welcome/_404';
in application/controllers/welcome.php
function _404(){
$this->load->view("my404_view");
}
And this should be sufficient in the current version of CI.
Including headers and footers in the default error 404 page seems to be a common problem for CodeIgniter users. I would like to add this link: Simon Emms's comments at http://www.simonemms.com/2011/05/06/codeigniters-404-override-problem/ because he describes the problem so clearly.
I have tried the suggestions at http://maestric.com/doc/php/codeigniter_404 and played around with Simon Emms's ideas, and others, but just can't implement them. I'm a bit of a novice at PHP and CodeIgniter, so that might be because of ignorance. That said, it is difficult to ensure that you put the suggested subclasses in the right places and configure, for instance, routes.php correctly. After 3 days of trying the various rather complicated ideas, it occurred to me that I could just use an include statement in the default error 404 page. The only difficulty was figuring out the path to pass to the include statement.
In /system/core/Exceptions.php line 146, I found the CodeIgniter developers use APPPATH. You then just have to append the path to the header and footer pages you want to include.
My new default error 404 page now looks like this:
<?php
include APPPATH.'/views/templates/header.php';
?>
<div id="container">
<h1><?php echo $heading; ?></h1>
<?php echo $message; ?>
</div>
<?php
include APPPATH.'/views/templates/footer.php';
?>
This seems a much easier solution to me than trying to change the core classes in CodeIgniter.
There is quite a bit of information on this.
http://maestric.com/doc/php/codeigniter_404
http://www.nickyeoman.com/blog/apache/90-htaccess-404-page
http://hasitha.posterous.com/customising-error-pages-on-codeigniter (archived)
Related
I'm currently working with codeIgniter framework and the problem i'm facing is with template integration with it. In view pages the links aren't working.Like if i've to navigate using
<p>Contact
i changed this with
<li><strong>Contact</strong></li>
And this:
Contact</li>
but nothing happens. May i know how to navigate to other views using these menue tags?? I've also loaded views from controller but the result is same.
Thanks in advance..
What do you mean by saying that nothing happens? do you get any error? does the page even redirect? if the page redirects and you still cannot see any errors put this code in the head of your index.php for debugging purpose: error_reporting(E_ALL); ini_set('display_errors', '1'); and watch the errors you are getting.
There could be a few reasons for it:
you didn't loaded the Helper: $this->load->helper('url');
you should configure the base_url in your config.php: $config['base_url'] = '';
I created a template on WordPress and I made an html form. It works well in HTML but doesn't work when used on WordPress. It seems that it doesn't find my contact-send.php page and it displays a 404 Error page.
My permalinks were on default and it didn't work.
Does anyone know how to fix this?
If any of my code is needed, I'll post it. I just didn't because I think it's not a code error once it doesn't find contact-send.php.
Use an absolute URL for the target of your form instead of just action="contact-send.php".
But unless you have particularly unusual requirements for your contact form, you will likely have better results using one of the many popular contact form plugins like Contact Form 7.
Using a well-maintained plugin ensures stability, and more importantly, security. Don't reinvent the wheel if you don't have to.
Your problem can be caused due to 3 reasons.
Giving wrong path in action tag. Using <?php echo get_template_directory_uri(); ?>/contact-send.php will solve this problem.
Missing contact-send.php page in the themes folder. This problem can be solve by adding the page to the themes folder.
Improper .htaccess file. This can be solved by recreating the code for your .htaccess file from Dashboard > Permalinks and paste it in the .htaccess file in the WordPress root directory.
I am giving the explanation in the assumption that your template file is directly in the themes folder.
Add <?php echo get_template_directory_uri(); ?>/contact-send.php. When you write contact-send.php only then it don't find your file which is in your theme. So use this <?php echo get_template_directory_uri(); ?>/contact-send.php in form action. This change may be helpful.
How I can handle my 404 custom page (and possibly other errors)?
I just tried in routing part to add
GET /#codes /WebController->error
Where my Class WebController handles error, and for 404 i solved (partially). In effect it works for
http://mydomain.ext/itdoesntexists
but if i recall a
http://mydomain.ext/sub/maybe_another_sub/and_so_on/doesnt_exist
My route (of course) doesn't work.
Btw, with that route in every case it doesn't push 404 header (just a maniac-vision of things, i'm thinking to Google looking for a resources and it doesn't receive a "pure" 404).
Thank you
You don't have to define a route for this. F3 will automatically generate a 404 status code for any non-defined route.
If you want to define a custom error page, you need to set the ONERROR variable.
Here's a quick example:
$f3->route('GET /','App->home');
$f3->set('ONERROR',function($f3){
echo \Template::instance()->render('error.html');
});
$f3->run();
with error.html defined as:
<!DOCTYPE html>
<head>
<title>{{#ERROR.text}}</title>
</head>
<body>
<h1>{{#ERROR.text}}</h1>
<p>Error code: {{#ERROR.code}}</p>
</body>
</html>
Now if you call any non-defined route like /foo, the template error.html will be rendered with a 404 status code.
NB: this works for other error codes. Other error codes are triggered by F3 or your application with the command $f3->error($status), $status being any valid HTTP status code (404, 500, 403, etc...)
I would like to have the page on user/sidebar on the right in the template design.
Normally, I would include a php file. But I am using Kohana Framework so I have created a view and a controller for this sidebar, and exists on mysite.com/user/sidebar
Now how would i <?php include "/user/sidebar"; ?> correct? I get no such file og dir error for this. I tried full url, but allow_url_include=0
Just looking through the Kohana documentation...
It seems like you can include a "request" inside a view with the following command.
<?php echo Request::factory('user/sidebar')->execute() ?>
See this page for more info: http://kohanaframework.org/3.0/guide/kohana/mvc/views
AndrewR's comment is close. For Kohana 3.2, you'll want to load a view within a view and not a request within a view:
<?php echo View::factory('/user/sidebar'); ?>
or
<?php include Kohana::find_file('views', 'user/sidebar') ?>
Either is acceptable to do.
I'm following CodeIgniter's tutorial "Create a blog in 20 minutes" and I am having trouble getting the helper, anchor and Scaffolding functions to work.
I can't seem to create links on my HTML page using the helper and anchor functions.
I put
$this->load->helper('url');
$this->load->helper('form');
in the constructor under
parent::Controller();
and
<p><?php echo anchor('blog/comments','Comments'); ?></p>
within the foreach loop as specified in the tutorial. But Im not getting the links to appear.
When I viewed the source as instructed in the video, this line was missing (but it was in in the video):
<form method= "post" action = "http://www.example.com/CodeIgniter/index.php/blog/comment_insert">
Secondly, I keep getting a 404 Page Not Found error whenever I try to access CodeIgniter's Scaffolding page in my browser, like so:
localhost/codeignitor/index.php/blog/scaffolding/mysecretword
I can access
localhost/codeignitor/index.php/blog
just fine. I followed CodeIgnitor's instructions in their "Create a blog in 20 minutes" by storing my database settings in the database.php file; and automatically connecting to the database by inserting "database" in the core array of the autoload.php; and I've added both
parent::Controller(); and $this->load->scaffolding('myTableName') to blog's constructor. It still gives me this 404.
Any assistance will be appreciated. Thanks in advance?
Scaffolding is deprecated, but it hasn't been removed until 2.0, and still works in 1.7.2.
You have /scaffolding/ in the URL which isn't necessary, you just use your scaffolding trigger.
I'm not sure why your helpers aren't working, your syntax looks good, unless you don't have any data in your foreach loop. the <form...> line comes from calling <?php echo form_open('form_controller_or_whatever'); ?>
localhost/codeignitor/index.php/blog/mysecretword
is just enough ....
check out this site:http://www.schobbing.de/user_guide/general/scaffolding.html you'll get a clear understanding ....