Trying to include template in the error 404 page - codeigniter

Im trying to get a error 404 page in the template which Im using, but it's not working. I have tried MY_Exceptions also.
There is view page called error404 and code goes like this:
<h1><?php echo $heading;?></h1>
<?php echo $message; ?>
Just to display error msg.
Im trying to include the below line to display error in my template, but it's throwing error:
$this->load->view("pages/template.php");
What should I do to display customized error 404 in my template using codeigniter.

It should be like this, and pass message and heading like this :
$data['heading'] = 'heading';
$data['message'] = 'your message';
$this->load->view("pages/template",$data);
instead of this
$this->load->view("pages/template.php");
Your view template.php:
<h1><?php echo $heading;?></h1>
<?php echo $message; ?>
for more :https://www.codeigniter.com/user_guide/general/views.html#adding-dynamic-data-to-the-view

Related

Changing error delimiter to empty in codeigniter

i want to change the form error wrapper. I don't want any wrapper no div no <p> i have used this code <?php echo form_error('inv_data_val','<div>','</div>'); ?> it do adds the div but when i used <?php echo form_error('inv_data_val','',''); ?> it still shows p
http://www.codeigniter.com/userguide3/libraries/form_validation.html#changing-the-error-delimiters
$this->form_validation->set_error_delimiters('', '');
In your controller.

CodeIgniter adjusting url when passing parameters to controler

Ok i have records from database listed in view file, so u can see i wanna pass values to controler via href by update/grab function controler
echo $this->pagination->create_links();
br().br();
foreach ($query->result() as $q): ?>
<?php echo $q->info . br()?>
<?php endforeach; ?>
it works for first page in my pagination, when i am on some other page when i clicked on on record, instead passing parametars to controler when i clicked in keep adding url for example http://localhost/z/records/users/update/grab/3/update/grab/1/update/grab/1/update/grab/1/trtr
So error is when i have in url, when i am on second page in pagination
http://localhost/z/records/users/2
works only when i am on first page
http://localhost/z/records
is there a way to solve this proble. Will it works if i some how adjust routes??? Need help, please help me its very important
Try changing your link to an absolute URL:
<a href="/z/update/grab/<?php echo $q->id;?>/<?php echo $q->info; ?>">
Or adding a correct relative URL base to the header of your pages:
<base href="/z/" />
Codeigniter routes allow you to do this:
$route['post/(:any)/comment/(:any)'] = "posts/comments/$1/$2";
Then in the controller, the function inside my posts controller would work like this:
public function comments($one, $two) {
echo $one."-".$two;
}
so if you hit the url "/post/111/comment/222" the output would be
111-222

How to display error or success message in a template file?

I want to show message on some condition in a template file(custom module template file).I am having following code.
<?php
if(count($collection)): ?>
<?php foreach($collection as $coll): ?>
some calculations
<?php endforeach; ?>
<?php else: ?>
<?php $message = $this->__('There is no data available'); ?>
<?php echo Mage::getSingleton('core/session')->addNotice($message);?>
<?php endif;?>
But this is not working properly. The message is displayed on other pages not on the same page.
If you really need to implement that right in the template, you may use the code below:
<?php echo $this->getLayout()->createBlock('core/messages')->addNotice('My Message')->toHtml(); ?>
But the solution described by Amit Bera sounds like a better way to resolve it.
Muk,According to your code
Mage::getSingleton('core/session')->addNotice($message);
add an notice to magento.This is code set notice to session and which is reflecting on page refresh according php session ,a session variable set value is reflecting after page refresh.
If you already added this notice on other page before came to your file then ,you need to add core/session to custom module template file controllers file.
Code is $this->_initLayoutMessages('core/session');
In controller you need below code in controller.
/* load the layout from xml */
$this->loadLayout();
$this->_initLayoutMessages('core/session');
/* rendering layout */
$this->renderLayout();
Read more at inchoo blog
I found that $this->loadLayout() is what reads and clears messages from the session, therefore if you add messages before calling $this->loadLayout() then those messages should be displayed on the current page.
Example:
public function chooseFileAction() {
// a quick and dirty way to find the larger out of post_max_size and upload_max_filesize
$post_max_size = ini_get('post_max_size'); $post_max_size_int = str_replace('K', '000', str_replace('M', '000000', str_replace('G', '000000000', $post_max_size)));
$upload_max_filesize = ini_get('upload_max_filesize'); $upload_max_filesize_int = str_replace('K', '000', str_replace('M', '000000', str_replace('G', '000000000', $upload_max_filesize)));
$maxsize = $post_max_size_int < $upload_max_filesize_int ? $post_max_size : $upload_max_filesize;
// display max file size to user in a message box
$msg = 'Max file size: ' . $maxsize;
Mage::getSingleton('core/session')->addNotice($msg);
$this->loadLayout();
$this->_title($this->__('Catalog'))->_title($this->__('File Upload'));
$this->_setActiveMenu('catalog/customfileupload');
$block = $this->getLayout()->createBlock('customfileupload/adminhtml_customfileupload_choosefile');
$this->_addContent($block);
$this->renderLayout();
}
Caveat: this is tested in Magento 1.9, not 1.7.

Change in APC for Magento stops SimplePie from working

We have been using SimplePie on our Magento install to pull our blog posts into our home page without issue for several months now. Due to some other issues with Magento, we had our web host turn off opcode in APC. Once we did that, the next hourly update of SimplePie stopped the loading of the home page and returns the following error in Apache:
[Wed Jan 18 09:59:57 2012] [error] PHP Fatal error: Class 'Zend_Log' not found in {server root}/lib/SimplePie/simplepie.inc on line 738
I am at a bit of a loss on what is happening and what to do to fix it. SimplePie is delivered as a banner/widget so if I put it on a different category page I get the same results. (Page stops at SimplePie command) I was hoping it would be something simple like the change is forcing the old chached RSS to remain and can not be modified but I am not sure.
Any help would be very appreciated!
The code for SimplePie is unaltered and is version 1.2.1. I have a page /app/design/frontend/default/default/template/page/html/blog.phtml which has the following code.
<div class="col-narrow right sidebar-blog">
<h2>Our Gardening Blog</h2>
<?php
// Make sure SimplePie is included. You may need to change this to match the location of
require_once('lib/SimplePie/simplepie.inc');
// We'll process this feed with all of the default options.
$feed = new SimplePie();
// Set which feed to process.
$feed->set_feed_url('http://blog.americanmeadows.com/feed/');
// Run SimplePie.
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8
$feed->handle_content_type();
/*
Here, we'll loop through all of the items in the feed, and $item represents the
current item in the loop.
*/
foreach ($feed->get_items(0,2) as $rss_item):
?>
<div class="article-teaser">
<p><span><?php echo $rss_item->get_date('F j, Y'); ?></span></p>
<h2 class="article-title"><?php echo $rss_item->get_title(); ?></h2>
<?php if ($rss_item->get_item_tags('', 'thumbnail')) {$thumbnail = $rss_item->get_item_tags('', 'thumbnail'); echo "<img src='" . $thumbnail[0]['data'] . "'>"; } ?>
<p><?php echo $rss_item->get_description(); ?> <a class="more" href="<?php echo $rss_item->get_permalink(); ?>" target="_blank">Continue Reading</a></p>
</div>
<?php endforeach; ?>
</div>
I then have a banner which calls only the following
{{block type="page/html" template="page/html/blog.phtml"}}
I include that banner in the left column widget on our home page to have it display.
The lines in SimplePie is throwing the error is
function SimplePie($feed_url = null, $cache_location = null, $cache_duration = null)
{
// Other objects, instances created here so we can set options on them
$this->sanitize =& new SimplePie_Sanitize; /* Error is thrown here */
// Set options if they're passed to the constructor
if ($cache_location !== null)
{
$this->set_cache_location($cache_location);
}
I think that is what you need but am happy to post more.
My only thought here is that somewhere something is setting Zend_Log as an error logger. Check for set_error_handler() in your code and see if that's being registered anywhere. (You could double check that by causing an error yourself with trigger_error() and seeing what happens.)
As for why the error is occurring, I'd hazard a guess at that being because you're using 1.2.1 with PHP 4, which will give E_DEPRECATED errors when assigning new by reference (such as on that line).

$js in select dropdown in codeigniter

I have a js in a folder js. I call the file in the header.
I have the next code in my view:
<?php echo form_dropdown('mydropdown',$options) ?>
I need to pass the paramether $js, could you help me with the syntax?
$js = 'id="shirts" onChange="display(this,\'id1\',\'id2\');"';
<?php echo form_dropdown('mydropdown',$options, $js) ?>
When I see the source code of my dropdown I can't see the id="shirts", then I believe that the function javascript is not recognized.
What's my error. My codeigniter version is 2.0.
Thanks.
javascript should be the fourth parameter to this call. So add a null parameter in the third (which is for the selected value of the dropdown):
<?php echo form_dropdown('mydropdown',$options, null, $js) ?>
http://ellislab.com/codeigniter/user_guide/helpers/form_helper.html

Resources