cakephp 2.0 upgrade shell redirect() faulty? - shell

I am upgrading an application from cakephp 1.3 to 2.0 and running into some problems. I can't quite figure out what is going on behind the scenes with my redirect statements. This has been happening since I ran the upgrade shell.
If I put this in my controller the redirect works perfectly:
function redirect() {
$this->redirect(array('controller' => 'user', 'action' => 'partners'));
}
This, however, does not work for me:
function redirect2() {
echo 'made it';
$this->redirect(array('controller' => 'user', 'action' => 'partners'));
}
This isn't a function I am using, it is just the simplest form of the problem I have isolated.
I know I shouldn't be displaying things from the controller, but my question is what is going on behind the scenes that is causing the redirect to not function? The result for the redirect2() is it prints "made it" on the screen and then stops. No errors, no redirects, no showing the view for redirect2. I have checked the error logs and there are no errors.
The confusing thing is that when I was using 1.3 all my redirects worked fine, and now something isn't working with some of them.
Thanks for any help,

you are not allowed to echo anything except for http headers prior to a php redirect.

Related

Laravel doesn't authenticate on server but does on local machine

I just uploaded a project from my local machine via FTP and it seems that the live server is working differently after trying to log in.
On the live server it's not authenticating. It gets to the __construct on AuthController.php but goes right back without errors (again, on local it works fine).
I tried adding this in Authcontroller.php:
public function postLogin(Request $request){
die();
}
And it didn't even reach it on server (it did on local).
I tried playing with the routes and instead of this:
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
I did this:
Route::post('auth/login','Auth\AuthController#postLogin');
Route::get('auth/login','Auth\AuthController#getLogin');
Didn't help on the server (local still worked fine).
I tried clearing my browser's cache, artisan cache, artisan config cache and basically anything I could find.
I tried re-uploading files from local to the server and nothing seems to work.
The most important thing here (I think) is that when I created the postLogin function it didn't even go in. That should be a huge tip if I actually knew what that meant.
The log didn't give me any errors.
Thank you #Bagus Tesa for asking to see the login file!!!
In the action of the form I added a parameter I was using for something but for some reason that's what was screwing everything up.
The important thing is that it works now...
Thanks so much!

Magento API Call 503s

Everything in my Magento store is working ok, except for a route I created that calls the API:
$proxy = new SoapClient('SOAPCLIENTURL');
$sessionId = $proxy->login('USERNAME', 'PASSWORD');
$proxy->customerCustomerCreate($sessionId, array(
'email' => $email,
'firstname' => '',
'lastname' => '',
'password' => $password,
'website_id' => 7,
'store_id' => 7
));
When I comment out these lines, the route works fine. Any ideas why this 503s the page and how to fix it?
The code block that's causing your problem is a request to an external API that could fail for numerous reasons. The way you'd fix this is to monitor your server and Magento error and exception logs for errors, take a look at the error, and then fix the problem (or post the specific error to a site like this and ask for help).
You could also try running the above code snippet outside of a Magento context (in a stand along script) and see what sort of error you get.
If errors aren't showing up then you need to research how to setup your system for proper error handling.
Also, if you're setting up a Magento route and making an API call into the same system, there's no reason to use the SOAP or XML-RPC layer. Each Magento API section has a corresponding PHP object that contains all the logic. The above method is equivalent to
Mage::getModel('customer/customer_api_v2')->create(array(...));
With the real PHP class being at
app/code/core/Mage/Customer/Model/Customer/Api/V2.php
and the create method defined at
app/code/core/Mage/Customer/Model/Customer/Api.php

Yii Ajax success Javascript won't go away

I'm running Apache2 on Ubuntu 12.10, and yii 1.1.13
I have an ajax request that looks like this:
echo CHtml::dropDownList(
'id',
$model->value,
$model->values,
Array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('myurl'),
'update'=>'#myId',
'data'=>array(
'first'=>'value',
'second'=>'value',
),
)
);
In the past, I tried adding a line after 'data' that looked like this:
'success'=>"function(html){jQuery("#myId").html(html)}});return false;}"
I've since deleted it. For some reason, this keeps showing up on my page.
I've tried the following:
Restarting entire server
Deleting entire browser cache, and even having a friend who has never seen the site before load it
Grep my entire web directory for that line of code
I have not been able to find any trace of this stupid line, but it won't go away. Please help, I'm starting to question my sanity.
'update'=>'#myId', // this line indicates which selector would be updated after ajax success
Because above line also renders the same what the removed code acts
'success'=>"function(html){jQuery("#myId").html(html)}})

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.

Session not starting on Cakephp 2.2.3

I'm having a strange issue with sessions on cakephp 2.2.3... my sessions are not starting on the webserver. I tried to use this code on a controller:
<?php
if ($this->Session->write('Test', 'hi')){
echo $this->Session->read('Test');
}
else{
echo 'bye';
}
and the output was bye on webserver, and hi on localhost.
So, I checked further, and found that the method CakeSession::start() is always returning false. This started to happens today, and i couldn't realize what may be causing this...
my session configuration on core.php is
Configure::write('Session', array(
'defaults' => 'database',
'checkAgent' => true,
'timeout' => 31104000,
'cookie' => 'vejomun'
));
When setting debug to 2, I receive a lot of warnings like this:
Warning (2): ini_set() has been disabled for security reasons [CORE/Cake/Model/Datasource/CakeSession.php, line 484]
but it has always been like this, and the sessions was ok untill yesterday...
thanks in advance, and sorry for bad english.
EDIT:
if anyone has the same problem, it was just an blank line at the begin of the html.
at the top of page write
session_start();
if you write this line then and then php will compatible with session

Resources