I want to change the custom error message for file size upload without changing it from the core lang file. I have gone through the below code as the solution to previous asked similar question:
Codeigniter File Upload Custom Error Messages
But I am not sure as to where to use it. Can anyone guide?
Many thanks..
if your goal is to use this function in certain function,
you can create your custom validation, since you have can access $_FILES variable, and get the info of the file.
so before you called do_upload()
you have something similar to this :
if($_FILES['userfile'] > $somenumber) {
//error here
} else {
//ok to upload
$this->upload->do_upload();
}
You can also use form validation custom callback to implement that approach.
https://www.codeigniter.com/userguide3/libraries/form_validation.html#callbacks-your-own-validation-methods
Related
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.
I've a controller to create a controller. SiteController is an example.
public function createSiteController() {
$controller_name = "SiteController";
Artisan::call("make:controller",
[
"name"=>$controller_name
]);
}
It gives me following error.
file_put_contents(/Volumes/Data/www/cms/app/Http/Controllers/SiteController.php):
failed to open stream: Permission denied
Tried to set chmod("/Volumes/Data/www/cms/app/Http/Controllers", 0777), but it is not permitted.
Edit: Of course, i don't want to use 0777. It was just an example. I would never use that. I am just saying
So, I had a problem to create a controller using a controller. I was unable to do it using artisian command.
Why I need that?
I've created an artisian command. something like this. (php artisian cms:controller controllerName)
It should be extended to BaseAdminController rather than default Controller. So I've made a template to create a custom controller. Just like laravel itself does.
I've fixed this problem using below steps.
* First you need to make a new file in a temp folder.
* Manipulate/Change whatever you want in that file.
* and copy that file (Controller in my case) to your Controller folder using copy command.
I am working on codeigniter and I am making a login page. When i validate the credentials I wan to move the user to next view if the credentials are correct.
I am using following command to redirect the user but it is merging the new view to the existing view and the url being shown in the browser is also getting appended.
$this->load->view('DataEntry');
URL before executing this command :http://127.0.0.1:8080/ci/
URL after executing this command : http://127.0.0.1:8080/ci/index.php/CI/DataEntry
how can i redirect the user from one view to another without appending the url and what is the right way to do it ?
I am an abolute beginner. so accept my apologies for dumb questions.
In general, it should be something like this:
//pseudo code
if ($validation_passed)
{
redirect('secret_page_controller/secretpage_method');
}
else
{
//if validation failed
$this->load->view('view_where_login_form_is');
}
Follow basic example from docs.
Please, format your code appropriate and add controller/method(s) code.
I am trying to treat the invalid requests on my Laravel app, something like redirecting to the root will work just fine, but I can't manage to do it.
In the documentation and around stackoverflow I saw this is always the solution:
App::missing(function() {
# handle the error
});
I thought that would just go to the routes file but no. Then I saw in some post it should be in the app/start/global.php file but it still didn't work.
In the docs it says I can "register an error handle". Is that what I should do? What does this mean? What should I do?
Ultimately this can be put anywhere, but app/start/global.php is probably the best place for it.
App::missing(function($exception)
{
return Response::view('errors.missing', array(), 404);
});
Try putting this in there. In fact, if you've just setup a fresh installation, you should already have one there.
Here is how you can register an error handler, like so;
App::error(function(Exception $exception, $code)
{
//Now you can check for different exceptions and handle each on their own way.
}
This will be for PHP general Exception class which will make all exceptions go here, but you can change Exception to the specific Exception class of you own and handle it accordingly.
App::missing will generally be called when a page within your site has not been found, allowing you to show a default page for when users have found a non existing page. So if you are wanting to handle missing pages, use App::missing else use App::error.
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