laravel-3 core exception on new installation - laravel

I have a new installation of Laravel on a machine running ubuntu 12.04 LTS, Nginx, php-cgi, and Laravel v3.2.14
I am getting the following error.
Unhandled Exception
Message:
Undefined index: argv
Location:
DOCUMNET ROOT/laravel/core.php on line 218
EDIT:
I have managed to get a slightly more descriptive error by commenting out the error handling function in laravel //Error::shutdown(); on line 50 of DOCUMENT ROOT/laravel/laravel.php
Note that this line does not cause the error, it only seems to register a handler for the code that does.
Here is the error:
Unhandled Exception
Message:
A driver must be set before using the session.
Location:
DOCUMENT ROOT/laravel/session.php on line 109
Stack Trace:
DOCUMENT ROOT/laravel/session.php(150): Laravel\Session::instance()
DOCUMENT ROOT/laravel/laravel.php(195):
Laravel\Session::__callStatic('save', Array)
DOCUMENT ROOT/laravel/laravel.php(195): Laravel\Session::save()
DOCUMENT ROOT/public/index.php(34): require('/mona/developme...')
{main}
These are the code blocks causing the error:
if (Config::get('session.driver') !== '')
{
Session::save();
}
Which calls this function in DOCUMENT ROOT/laravel/session.php
public static function __callStatic($method, $parameters)
{
return call_user_func_array(array(static::instance(), $method), $parameters);
}
$method contains the string 'save', and $parameters is an empty array.

Laravel thinks that it is being accessed by cli if you are using php-cgi.
The solution is Modifying DOCUMENT ROOT/laravel/request.php like this:
public static function cli()
{
// This is a hack to make laravel work with fast-cgi
// Added by David - 03/27/13
if(!array_key_exists('argv', $_SERVER)) return false;
return defined('STDIN') || (substr(PHP_SAPI, 0, 3) == 'cgi' && getenv('TERM'));
}
Checking if the $_SERVER super global has the 'argv' key before returning false permits cli to continue to function while using php-cgi.

Inspired by your answer, this worked for me:
public static function cli()
{
if(array_key_exists('HTTP_HOST', $_SERVER)) return false;
return defined('STDIN') || (substr(PHP_SAPI, 0, 3) == 'cgi' && getenv('TERM'));
}

Related

Error creating session context via php sdk

The goal is to create a session context via the PHP V2 SDK like this:
$session = $this->contextsClient->sessionName($this->projectId, $this->sessionId);
$contextName = $this->contextsClient->contextName($this->projectId, $this->sessionId, 'test-context-name');
$context = new Context();
$context->setName($contextName);
$context->setLifespanCount(2);
$context->setParameters(["test-param-key" => "test-param-value"]);
return $this->contextsClient->createContext($session, $context);
The code works fine without the $context->setParameters(["test-param-key" => "test-param-value"]); part. I need to add parameters to the context though.
The error I get is:
Exception {#3554
#message: "Expect message.",
#file: "/home/vagrant/code/vendor/google/protobuf/php/src/Google/Protobuf/Internal/GPBUtil.php",
#line: 197,
}
I followed the errors trail and the problem is Google's code in line 197:
public static function checkMessage(&$var, $klass)
{
if (!$var instanceof $klass && !is_null($var)) {
throw new \Exception("Expect message.");
}
}
is trying to assert if the array passed to the setParameters function is an instance of \Google\Protobuf\Struct class in this snippet right here
public function setParameters($var)
{
GPBUtil::checkMessage($var, \Google\Protobuf\Struct::class);
$this->parameters = $var;
return $this;
}
I would be really glad if someone could help me. I spent a lot of hours trying to figure this out and nothing yet
As the error message states, the parameters need to be of type \Google\Protobuf\Struct. Also, each of the values need to be of type \Google\Protobuf\Value. For your particular example, you could do the following:
$paramValue = new \Google\Protobuf\Value();
$paramValue->setStringValue("test-param-value");
$parameters = new \Google\Protobuf\Struct();
$parameters->setFields(["test-param-key" => $paramValue]);
$context->setParameters($parameters);
You can look the implementation of these two classes here:
https://github.com/google/protobuf/blob/master/php/src/Google/Protobuf/Value.php
https://github.com/google/protobuf/blob/master/php/src/Google/Protobuf/Struct.php

Deprecated: Non-static method SmartyPaginate::connect() should not be called statically

I am using SmartyPaginate plugin for SMARTY Template and its throwing 6-7 errors of same type from this very plugin. All error came up when I upgraded to PHP 7. Although I can disable error showing but I would really like to resolve that permanently.
Deprecated: Non-static method SmartyPaginate::getCurrentIndex() should not be called statically in libs\plugins\function.paginate_prev.php on line 58
Codes that are throwing errors.
if (SmartyPaginate::getCurrentIndex($_id) === false) {
$smarty->trigger_error("paginate_prev: total was not set");
return;
}
I resolved all the static errors. I did with following solutions.
Old Code
if (SmartyPaginate::getCurrentIndex($_id) === false) {
$smarty->trigger_error("paginate_prev: total was not set");
return;
}
New Code
if ((new SmartyPaginate)->getCurrentIndex($_id) === false) {
$smarty->trigger_error("paginate_next: total was not set");
return;
}

Server Migration fatal error on contact forms in CodeIgniter

I've been trying to pick my way through this error but I feel like I'm getting nowhere.
We're in the process of migrating a website from one server to another. All pages seem to work on the new site except for the contact form pages which appear to be trying to use 'form_helper.php'. These pages work correctly on the old server but not on the new one. I get an error of:
Fatal error: Call to undefined method CI_Loader::is_loaded() in C:\DATA\XXXX.com\www\application\helpers\form_helper.php on line 1038
Line 1038 of form_helper.php has the following on it:
if (FALSE !== ($object = $CI->load->is_loaded('form_validation')))
Any ideas would be GREATLY appreciated as I'm not that familiar with CodeIgniter.
Thanks in advance...
EDIT:
So I've worked out how to seemingly fix it... If I comment out the following code in the form_helper file, the page loads with no error:
/*if (FALSE !== ($object = $CI->load->is_loaded('form_validation')))
{
if ( ! isset($CI->$object) OR ! is_object($CI->$object))
{
return $return;
}
return $CI->$object;
}*/
Is this a bad idea? The full function now looks like this:
if ( ! function_exists('_get_validation_object'))
{
function &_get_validation_object()
{
$CI =& get_instance();
// We set this as a variable since we're returning by reference.
$return = FALSE;
/*if (FALSE !== ($object = $CI->load->is_loaded('form_validation')))
{
if ( ! isset($CI->$object) OR ! is_object($CI->$object))
{
return $return;
}
return $CI->$object;
}*/
return $return;
}
}
Make sure you have moved any array values in application/config/autoload.php from $autoload[‘plugins’] to $autoload[‘helpers’] or you will notice stuff break.
is_loaded() function is defined in Code/common.php Make sure the function is in right place.

Prototype Cannot call method 'get' of undefined

The Chrome console is giving me this error:
Uncaught TypeError: Cannot call method 'get' of undefined
I search that line and found this:
function _createResponder(element, eventName, handler) {
var registry = Element.retrieve(element, 'prototype_event_registry');
if (Object.isUndefined(registry)) {
CACHE.push(element);
registry = Element.retrieve(element, 'prototype_event_registry', $H());
}
var respondersForEvent = registry.get(eventName);
Uncaught TypeError: Cannot call method 'get' of undefined
if (Object.isUndefined(respondersForEvent)) {
respondersForEvent = [];
registry.set(eventName, respondersForEvent);
}
This seems to be happening when a "null" element is passed to the function on an event binding. Try adding the following before the second line (var registry = ...)
if (element === null) return;
This will basically prevent any further processing within this function, which should not be necessary when the element is null.
I haven't found any issue with doing this on Magento, but please let me know if there is any problem with using this fix.

I'm getting an invalid uri error when migrating a Magento 1.6.1 install to new Dedicated Server

I'm getting the following error when migrating a Magento install to a new Dedicated server
I pretty experienced at cloning and migrating Magento but I can't figure out whats wrong here.
I have checked the new server for compatibility and thats fine..
This error is normally thrown when there is an underscore in the uri . i have tried different subdomains but keep getting the error. I have just migrated the same site to my dev server and it works fine - any ideas ?
Trace:
/home/shushush/public_html/shoponline/magento/lib/Zend/Uri.php(143): Zend_Uri_Http->__construct('http', '//www.shushusho...')
1 /home/shushush/public_html/shoponline/magento/app/code/core/Mage/Core/Model/Store.php(712): Zend_Uri::factory('http://www.shus...')
2 /home/shushush/public_html/shoponline/magento/app/code/core/Mage/Core/Controller/Varien/Front.php(313): Mage_Core_Model_Store->isCurrentlySecure()
3 /home/shushush/public_html/shoponline/magento/app/code/core/Mage/Core/Controller/Varien/Front.php(161): Mage_Core_Controller_Varien_Front->_checkBaseUrl(Object(Mage_Core_Controller_Request_Http))
4 /home/shushush/public_html/shoponline/magento/app/code/core/Mage/Core/Model/App.php(349): Mage_Core_Controller_Varien_Front->dispatch()
5 /home/shushush/public_html/shoponline/magento/app/Mage.php(640): Mage_Core_Model_App->run(Array)
6 /home/shushush/public_html/shoponline/magento/index.php(80): Mage::run('', 'store')
7 {main}
The problem was due to '_' . It won't recognise the underscore.
Looking at your call stack, it appears this is the method that triggers the error/exception you're seeing
Zend_Uri_Http->__construct
Jumping to the source of that file, I'm guessing (since you didn't include the error text) this is the exception you're seeing.
#File: lib/Zend/Uri/Http.php
protected function __construct($scheme, $schemeSpecific = '')
{
//...
if ($this->valid() === false) {
#require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Invalid URI supplied');
}
//...
}
Taking a look at the definition of the valid method
public function valid()
{
// Return true if and only if all parts of the URI have passed validation
return $this->validateUsername()
and $this->validatePassword()
and $this->validateHost()
and $this->validatePort()
and $this->validatePath()
and $this->validateQuery()
and $this->validateFragment();
}
you can see 7 methods Zend/Magento calls to determine if the URI is valid or not. One of these is failing. I'd recommend adding some temporary debugging code to determine which method is returning false
public function valid()
{
var_dump($this->validateUsername());
var_dump($this->validatePassword());
var_dump($this->validateHost());
var_dump($this->validatePort());
var_dump($this->validatePath());
var_dump($this->validateQuery());
var_dump($this->validateFragment());
// Return true if and only if all parts of the URI have passed validation
return $this->validateUsername()
and $this->validatePassword()
and $this->validateHost()
and $this->validatePort()
and $this->validatePath()
and $this->validateQuery()
and $this->validateFragment();
}
Then, once you know that, you can look at the definition of the method that's returning false and determine which characters it's failing on.

Resources