codeigniter 404 function is not woking when function calling inside controller - codeigniter

I have set 404_override in route.php so that when there is no correspondent controller it will redirect to my error page
But my question is if there is no function inside the controller it is not redirecting properly
example: http:example.com/search/function_name
here search controller is there but the function_name not exist, how I can redirect to error page in this scenario ?
Your help will be really appreciate!

If you have set up the 404_override properly it will work as intended. You need to pass the controller method in which you are showing your custom 404 page else it would not work.

Create 'index' function in your error controller. Then you do not have to mention the function name in 404_override.

Related

Laravel 5 -- Redirect in Controller is not working in AJAX call

Important: this comes from ajax call.
Everything works perfectly except:
use Illuminate\Routing\Redirector;
public function my_call() {
return redirect()->route('page-1');
}
Throws 500 error.
return view('page-1') works without problems.
Maybe anybody sees what I am doing wrong?
Thank you.
Do you have an actual route with the name that you are using, you cannot redirect to a view as these are returned by routes
Apperantly you cannot do this on server side if you do AJAX call:/
Here an explanation: https://laracasts.com/discuss/channels/vue/redirect-after-ajax-post-request
It's for vue but I believe it applies universally for ajax.

Dompdf Laravel Test

I am having problems resolving this issue. I want the user to be able to download a report when pressing the button. I keep on getting Action not defined, and if I change my route it will simply not load the app.
Any help would be appreciated.
/************View***************/
<button>Download PDF</button>
/*************Controller****************/
public function pdf($id){
$report=Report::findorFail($id);
$pdf = PDF::loadView('reports.show', compact('report'));
return $pdf->download('server_report.pdf');
}
You need to have your action defined in a route.
For example:
Route::get('pdf','ReportController#pdf');
Also, make sure that if ReportController has a resource route then the pdf route goes above it.

Magento Redirect from Observer

I am having trouble to create a working redirect in Magento from an observer.Apart from that I need to understand why the exception just like we do in controller does not work in Observer.
The typical exception done in controller is like below (adminhtml controller)
$message = $this->__('Exception Message.');
Mage::getSingleton('adminhtml/session')->addError($message);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
Somewhere in the blog I read about the below method to redirect from observer.
Mage::getSingleton('core/session')->addError('Exception Message.');
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
Mage::app()->getResponse()->sendResponse();
exit;
I don't understand the basic redirection difference when doing with an observer and controller.
Why controller redirection does not work when used in observer.
Please help me out and explain.
Thanks a lot in advance.
See below link and i also have posted code
it might help you.
Source : http://aaronbonner.io/post/418012530/redirects-in-magento-controllers
Redirects in Magento Controllers
In Zend Framework controllers, to output something other than html you will want to disable ViewHelper defaults along with some of the other magic ZF typically weaves.
In Magento, the same thing applies when doing a controller redirect.
I noticed on PHP 5.2 a redirect seemed to be ignored whereas my Macports 5.3 setup it worked. Turns out I was missing a trick, and so a proper redirect in Magento is done as follows:
In MyPackage/MyModule/controllers/MyController.php :
$this->_redirectUrl($this->getUrl('http://www.someurl.com/someresource'));
$this->setFlag('', self::FLAG_NO_DISPATCH, true);
return $this;
Without the setFlag call, your redirect will be ignored. The return call stops any further code execution and sees your redirect get actioned.

Zend Framework non-existent controller redirects to home page?

When I type an invalid url (non-existent controller), it displays the homepage rather than return a 404 Page Not Found page. Does anyone know the possible reason?
Thanks
Have checked if there is any plugins are registered in the bootstrap and if is it configured to catch the exceptions or set any ACL mechanisms.
Also check the error controller too. may be there is some forwarding methods implemented there.
Hi i've had the same problem and i now know how to fix it:
within the bootstrap have the following init
function _initModules()
{
$this->bootstrap('frontController') ;
$front = $this->getResource('frontController') ;
$front->addModuleDirectory(APPLICATION_PATH . "/modules");
$front->setParam("useDefaultControllerAlways", false);
}
Setting 'useDefault....' will use the default controller when a 404 occurs.
You should also make sure your error controller is setup correctly

CakePHP redirect method not redirecting

I am trying to redirect to a new page using CakePHP redirect method but for some reason the redirect is not working. The code I am using to redirect is
public function update_sticky_postition_in_db()
{
$this->autoRender = false;
... // Save info to database
$this->redirect(array('action' => 'tool'));
}
Where tool is the name of the view I am tring to redirect to. To try and speed the process of finding the problem I have checked few things and think I have found the cause of the problem. Basically I am trying to redirect to the view that is currently active which I think is part of the reason why it is not redirecting. I have read that it might have something to do with caching of the page but I am not sure how to solve that issue.
Also when using firebug I can see the redirect is sending a GET request but after that nothing is happening. Do I have to do something with the GET request or should Cake handle that for me. Also I have checked the URL of the GET and it is correct.
It is located within the controller with the correct name as I can view the original tool page.
Also the update_sticky_postition_in_db() method does not have a view (hence why the auto render is set to false), its intended purpose is to update a row in the database from an ajax call.
From your post it seems you're firing the update_sticky_postition_in_db() using ajax call, so that the redirection will not work.
You can do redirection using JavaScript within ajax success method.
In order to do that, you may send some json_encode() message from you above method and checking that status within ajax success method you can do a redirect using window.location.

Resources