When I set:
error_reporting(E_ALL);
ini_set('display_errors', '1');
Hundreds of warnings and strict messages but no errors, locally it works but not on site. When I make a GET request it works but same url sending a POST request doesn't work.
I think it's some plugin causing this but hard to track down when Joomla happily gives me a blank page with 200 response.
In firebug I can't see the response, it only gives me:
Reload the page to get source for: the_url
This is in the /components/com_doctrine/doctrine.php
$route=JRequest::getVar('router', 'Tournament');
$controllerName = 'doctrineController'.$route;
include_once(dirname(__FILE__) . '/controllers/'.$route.".php");
$controller = new $controllerName(JRequest::getVar('task', ''));
$controller->setEntityManager(bootstrapDoctrine());
//echo "something";die(0); will show here but not after the next line
// and only when I post values not on a get request
$controller->execute(JRequest::getVar('task', ''));
$controller->redirect();
In the controller I have:
//JoomlaDoctrineBootstrapper extends JController
class doctrineControllerTournament extends JoomlaDoctrineBootstrapper{
function __construct()
{
parent::__construct();
$this->registerTask( 'show','show' );
$this->registerTask( 'save','save' );
}
function show(){
echo "works only on get requests, not on post";
$model=$this->getModel('tournament');
$view = $this->getView('show','text');
$view->setLayout('default');
$model->em=$this->getEntityManager();
$view->data = $model->getTournamentAsJson();
$view->display();
}
Looks like a plugin messing with my post requests but don't know where to look for it. Client doesn't have a test environment set up and tried copying all 200+ thousand php files through ssh with a sql dump from the database but can't get it going locally.
Related
I am sending a mail and after mail is send I want to redirect user to a specific url
$mail = Mail::send('test.mail', ['a' => 'a'], function (Message $message) {
$message->to(['hod#vu.edu.pk', 'student#vu.edu.pk',]);
$message->from('stms#vu.edu.pk');
$message->subject('Test Mail');
});
// dd($mail);
return response()->redirectToRoute('allocate_supervisor')
->with('message', 'Supervisor Assigned and sent to HoD for approval.');
I have tried to return redirect()->route(), url(), and redirect('allocate_supervisor') but each time same issue.
dd($mail); works fine and shows output but on redirect it shows blank page.
Also request status code is 200.
Also tried
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
before return still no output
There are several ways to generate a RedirectResponse instance. The simplest method is to use the global redirect helper:
return redirect('/allocate_supervisor');
make sure 'allocate_supervisor' route must be present in your web.php file.
if you have named routes, you may use route() method.
return redirect()->route('/allocate_supervisor');
I was calling storePhase function from store function and returning response from storePhase function which was being overridden in store function and I was receiving blank page...
I moved this response code to store function and it worked fine.
I built a small blog where a editor can create articles and post it and users can read it without login.
The issue that I'm having is the following :
In production server, if a user try to access a blog article from the home by clicking on the 'Read more' button, gets a 500 internal server error.
I'm also using other parametric routes and they are working perfectly fine.
In development server, everything works fine.
Any idea of what could the issue's cause?
Thanks in advance
In the home page I'm rendering a list of all the articles via the PublicController's index() method with the following code :
public function index()
{
$articles = Article::all();
return view('welcome', compact('articles'));
}
And it works perfectly fine.
But when a user click on a item of the list should be redirected, via the 'show()' method of the Public Controller, to the article's details page but in reality the user is getting a 500 internal server error.
The show() method :
public function show($id)
{
$article = Article::find($id);
return view('article', compact('article'));
}
One thing that can help you is to logging the exceptions in your Handler.php file. This way you can see the error details (message, file and code line).
I have a guitar lessons site where there is an exercises table. The original developers placed some functions in ExercisePresenter to retrieve other bits of data associated with an exercise, such as its url.
Here is a function in ExercisePresenter that returns url for an exercise:
public function url()
{
return '/guitar-lesson-ex/' . $this->urlName() . '/' . $this->id;
}
So now I am creating an event on new exercise created so I can use pusher notifications. In the EventServiceProvider I have this:
public function boot(DispatcherContract $events)
{
parent::boot($events);
Exercise::created(function ($exercise) {
// need to update lesson difficulty
$lesid = $exercise->lesson_id;
$les = \App\Lesson::find($lesid);
$dif = $les->difficulty();
DB::table('lessons')
->where('id', $lesid)
->update(['difficulty' => $dif]);
// lets trigger NewExerciseEvent to send pusher notifications
$url = $exercise->url;
event(new NewExerciseEvent($message));
});
}
I thought in above code $url = $exercise->url; would work since I see $exercise->url used successfully in exercise views. But it is returning $url as null. Now, there is no url column in the exercise database, so I figure somehow when $exercise->url; is used in a view, laravel is figuring out that the ExercisePresenter is able to return the url.
I am debugging through PHPStorm, but when I get to $url = $exercise->url; and step in, I am just taken through various bits of laravel code that looks for a method, etc. I am not savvy enough with laravel to figure out what it is doing here differently than in the view (too bad we can't debug views...), but each time I try this $url is returned as null.
Any idea how to get this to work properly in my EventServiceProvider?
Thanks!
Figured it out:
$url = $exercise->present()->url;
I had been searching for how to use presenters but having just read (Laravel View Presenters From Scratch), everything is clear!
Sorry for posting prematurely.
i was create codeigniter controller like this :
function Home() {
parent::Controller();
if(!$this->session->userdata('id'))
redirect ('login');
$this->load->model('Home_Model');
}
but when i try to access the page, the redirect page now show. just show 404 not found but i was create login.php on controller and views also home_model.php on model.
what the problem with that code and how to fix that?
thank you
Because of this line: parent::Controller(), I assume that you are using CodeIgniter 1. Since you are building pages like home and login, I assume that you are starting building a new website. If my assumptions are right, I suggest you using the latest CodeIgniter (v2.1.0 at the moment, required PHP 5.1.6 or newer). You can grab a copy at CodeIgniter Home Page.
First of all, I think you should check your error reporting level. It should be something like error_reporting(E_ALL); for debugging. If not yet, turn it on and run the code again. Maybe you will get your own answer after that :)
After that, you should try the code below for your constructor to check that your home controller process as you expected.
function Home()
{
parent::Controller();
echo 'Home Class Initialized';
}
It should at least show 404 page. If it doesn't print out anything then we need more information. Maybe you should turn on logging and analyze your log files: look for /application/config/config.php: $config['log_threshold'] = 2;
If it print out 'Home Class Initialized' follow by a 404 message: please check if your controller have something like:
public function index()
{
echo 'Invoke default method';
}
If not yet, please add one. You may also want to take a look at using your own default method here
If it still a 404 then sorry, I have no idea. Maybe you should post more code.
If it print out 'Home Class Initialized' only: good. Now try this
function Home()
{
parent::Controller();
if ( ! $this->session->userdata('id'))
{
echo 'Redirecting to login page';
//redirect ('login');
}
$this->load->model('Home_Model');
}
If this print out Redirecting to login page, it's now time for you to uncomment //redirect ('login'); and check the login page. Follow the same path with step 1 & 2.
If not, check your session data: var_dump($this->session->userdata('id'). You could learn more about PHP falsehood here
After all, if it still fails, consider using __construct() of PHP 5
function __construct()
{
parent::__construct();
if ( ! $this->session->userdata('id'))
{
redirect ('login');
}
$this->load->model('Home_Model');
}
Other: if you use this $this->load->model('Home_Model');, I think you will have to call home_model like this $this->Home_Model->foo(); or there will be error access to NULL
I'm trying to unit-test my controller (Yii framework).
/**
* #dataProvider provider
*/
public function testActionEdit_view_login($controller){
$user = new CWebUser;
$user->id = 978;
$identity = new UserIdentity('me#test.com', '123456');
$user->login($identity);
$controller->actionEdit();
$output = ob_get_contents();
assertContains('Add/Change Profile Picture:', $output);
assertContains('bio', $output);
assertContains('specialties', $output);
assertContains('change login', $output);
assertContains('New Password', $output);
}
When I do
$user->login($identity);
in order to login, I get the following error:
session_regenerate_id(): Cannot regenerate session id - headers already sent
I've already tried buffering the output by putting this at the beginning of the class:
public static function setUpBeforeClass(){
ob_start();
}
I also put ob_clean() in setUp() and ob_end_clean() in tearDownAfterClass().
Still I get the message that headers have already been sent. There are no spaces or newlines in the file, when I comment out the specific test method, it works perfectly. The login() seems to cause the problem.
Anyone got ideas how to prevent this / maybe unit-test the controller differently?
Thanks,
MrB
Before your call to $user->login, add the following code:
$mockSession = $this->getMock('CHttpSession', array('regenerateID'));
Yii::app()->setComponent('session', $mockSession);
This overwrites the regenerateID method with a method that does nothing.
Adding ob_start() to the bootstrap also works, but there is no output from PHPUnit until everything has completed.
With this method, you can still see the progress as it is happening.
I upgraded from Yii 1.1.7 to 1.1.10 and the regenerateID method was added in 1.1.8 so I got this error today.
Got it. I had included some Yii files before the ob_start(), which seem to have printed the headers. Now I buffer that, too.