I am developing a website in codeigniter. While I am trying to access controller function it gives white space screen rather than error specific. I have tried to put error_reporting(e_all) in my function name but no luck.
Below is my controller function
function update_something($post)
{
error_reporting(e_all);
}
How to enable error in CI?
Related
After installing and configuring CI 4 I can see the home controller and the debug bar as normal (I'm in development mode).
There is a problem with error reporting. If I try to deliberately write some wrong PHP code, CodeIgniter overrides the normal PHP behaviour and hides the errors (in development mode!!).
Here's an example of deliberately adding a PHP error to the home controller:
<?php namespace App\Controllers;
class Home extends BaseController
{
public function index()
{
this is an error!! ()
return view('welcome_message');
}
}
Here's the output (which is not helpful with real errors):
No direct script access allowed
How can I set CodeIgniter 4 to show PHP errors? (the error is not even logged anywhere inside the server)
this problem happened when u delete this folder (app/view/errors) from view
I am trying to write an endpoint which exports the data from the users table i currently have into a CSV file which is downloaded upon clicking of a button. I have setup the controller, routes, export file, and added in the button within the view but everytime i go to click the button it just directs me to the admin/user/export then gives me a 404 but shouldnt it just stay on the same URL then just add the file to my downloads file?
This is the package i am using for Laravel
https://github.com/maatwebsite/Laravel-Excel
web route
Route::get('users/export', 'Admin\UserController#export')->name('users.export');
UserExport
class UsersExport implements FromCollection
{
public function collection()
{
return User::all();
}
}
Controller Function
public function export()
{
return Excel::download(new UsersExport, 'users.csv');
}
Summarise problem:
Everytime i click the button on the view page it directs to admin/users/export then gives me a 404 when i want it to just download the CSV file for the users.
Some help to see where i am wrong would be helpful!
Thanks.
The problem is that two of your routes conflict with each other.
Given the following two routes:
Route::get('users/{user}', 'Admin\UserController#show')->name('users.show');
Route::get('users/export', 'Admin\UserController#export')->name('users.export');
Currently Laravel assumes that when you are trying to access users/export you actually want to access users/{user} with export as the route parameter {user}.
Making sure that users/export is registered before users/{user} should solve your issue:
Route::get('users/export', 'Admin\UserController#export')->name('users.export');
Route::get('users/{user}', 'Admin\UserController#show')->name('users.show');
My code igniter project is returning 404 whenever I use method that I created in controllers. I have it running on Mac OS Mojave on Apache2.
There might be configuration or setting that I missed.
The codeigniter page works fine when opening http://localhost/myproject where I see the welcome page.
I have a 404 problem when I start using the new controller class. To make it simple, I created below "Pages.php" controller file inside application/controllers folder:
<?php
class Pages extends CI_Controller {
public function view()
{
echo "running the view method";
}
}
I expected the page to display "running the view method"
but the result is a 404 page at http://localhost/myproject/view or http://localhost/myproject/index.php/view.
it works by adding below in route.php
$route['(:any)'] = 'pages/$1';
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'm new at Laravel and I can't figure how to handle controllers (and ajax).
I have a button in a sidebar, and I want to show a page when it's clicked.
I have a view (which is the page i want to display in ajax) located in views/logs/system.blade.php
and a controller located in controllers/LogsController which has the following code -
class LogsController extends BaseController {
public function getLogs() {
return View::make('logs/system');
}
}
my routes.php has the code -
Route::get('/', 'HomeController#showWelcome'); // Works fine
Route::get('logs', 'LogsController#getLogs');
First things - how can I access the view I'm gettings in getLogs in a URL (localhost/mysite/public/logs doesn't work...)
Second - how can I access it in an ajax call?
I tried
$.get('logs', function(data) {
console.log(data);
});
but it doesn't work either. It gets 500 Internal Server Error....
Help please!
You should be able to go to: localhost/mysite/public/logs
if not, enable mod_rewrite in your apache and in your apache httpd.conf, set:
AllowOverride All
Most probably the server error 500 (in both cases) is caused by the fact that you have a mistake in the View::make() call. To utilize a view in subfolder you have to use the dot notation.
So correct the code
class LogsController extends BaseController {
public function getLogs() {
return View::make('logs.system');
}
}
and you should be good to go, the url should load fine, both in browser and in Ajax.
If you still have problems, check the Laravel Logs (probably path/to/app/storage/logs/...) as well as Apache Error Log (probably /var/log/apache2/error.log). I assume you are using Unix/Linux operating system.
The rewrite module was on.
I solved it by going to localhost/mysite/public/index.php/logs, this is the URL that it expects, maybe something in the .htaccess file is wrong.