How to put google map API in codeigniter? - php

I got my library from
http://biostall.com/codeigniter-google-maps-v3-api-library
and followed the instructions in
http://biostall.com/demos/google-maps-v3-api-codeigniter-library/
but i am receiving an error message
A PHP Error was encountered
Severity: 8192
Message: Methods with the same name as their class will not be constructors in a future version of PHP; Googlemaps has a deprecated constructor
Filename: libraries/Googlemaps.php
Line Number: 16
Backtrace:
File: C:\xampp\htdocs\test_map\application\controllers\Welcome.php
Line: 25
Function: library
File: C:\xampp\htdocs\test_map\index.php
Line: 292
Function: require_once
Anyone knows how to solve this problem?

Try with renaming
function Googlemaps($config = array())
{
if (count($config) > 0)
{
$this->initialize($config);
}
log_message('debug', "Google Maps Class Initialized");
}
to
function __construct($config = array())
{
if (count($config) > 0)
{
$this->initialize($config);
}
log_message('debug', "Google Maps Class Initialized");
}
If doesn't work, than library probably needs more code changes since it is code older than 2-3 years.

You need to change the name of class with CI_Googlemaps and the name of constructor with __construct

Related

A PHP Error: Only variables should be passed by reference in Codeigniter

I'm stuck in this error. Can someone help me out? I am using Codeigniter 3.1.10
Here's a snippet of my code in system/core/Common.php
function &load_class($class, $directory = 'libraries', $param = NULL)
{
static $_classes = array();
// Does the class exist? If so, we're done...
if (isset($_classes[$class]))
{
return $_classes[$class];
}
$name = FALSE;
// Look for the class first in the local application/libraries folder
// then in the native system/libraries folder
foreach (array(APPPATH, BASEPATH) as $path)
{
if (file_exists($path.$directory.'/'.$class.'.php'))
{
$name = 'CI_'.$class;
if (class_exists($name, FALSE) === FALSE)
{
require_once($path.$directory.'/'.$class.'.php');
}
break;
}
}
I keep on receiving this error message:
Notice: Only variables should be passed by reference in
/customers/5/d/b/tsoft.se/httpd.www/kanban/system/codeigniter/Common.php
on line 148
A PHP Error was encountered Severity: Notice
Message: Only variables should be passed by reference
Filename: codeigniter/Common.php
Line Number: 148
**Note : Line 148 is this return $_classes[$class];
As stated in a comment on this github issue, since you are using CodeIgniter version 3.1.10, you need to replace your system folder.
The file system/codeigniter/Common.php has been moved to system/core/Common.php on your version.

How to make an override for a function in a php file

I am using a module which is often updated by the developing company.
In one php file (cat_product_get.php) of this module is the here below function :
function getColSettingsAsXML()
Inside this function is the following code :
{
foreach($colSettings[$col]['options'] AS $k => $v)
{
$xml.='<option value="'.str_replace('"','\'',$k).'"><![CDATA['.$v.']]></option>';
}
}
Such code leads to the following warning :
PHP Warning: Invalid argument supplied for foreach() in ../cat_product_get.php on line 317
Line 317 is the following :
foreach($colSettings[$col]['options'] AS $k => $v)
To fix the warning, I added one line as follows :
if (is_array($colSettings[$col]['options']) || is_object($colSettings[$col]['options']))
{
foreach($colSettings[$col]['options'] AS $k => $v)
{
$xml.='<option value="'.str_replace('"','\'',$k).'"><![CDATA['.$v.']]></option>';
}
}
But at each module update, I have to amend again the cat_product_get.php.
I tried to convince many times the developer to add the suited line in his code.
But the developer refused to do it.
Is there a way to add somewhere an override to avoid the line addition at each module update ?
I am not a developer...
I thank you in advance for any reply.
Patrick
If the function is just a plain function, then it can't be done in PHP. You can't have duplicate function names.
If it is a function in a class (aka a method), you can extend that class and just rewrite the function, and use your class.
class Person
{
public function fixThisCrap()
{
return 'the wrong stuff';
}
// more functions
}
class MyPerson extends Person
{
public function fixThisCrap()
{
return 'the correct stuff';
}
// parent class functions will be available, no need to code
}

Can't load modules from libraries in CodeIgniter HMVC

I'm having a problem loading modules inside my template library in CodeIgniter HMVC. The reason I want to load a module in the template library is that I wish to use modules for sideboxes and other content boxes in my template.
PS: I am also using the Smarty template parsing system for CodeIgniter, but I doubt it has anything to do with the errors, but if you have reasons to believe otherwise, please, let me know.
What I tried to do
I tried to load the module in two different ways, and both presented with the same errors.
The errors
A PHP Error was encountered
Severity: Notice
Message: Undefined Property CI::$template
File: MX/Loader.php
Line Number: 141
-
A PHP Error was encountered
Severity: Notice
Message: Undefined Property CI::$template
Filename: MX/Controller.php
Line number: 57
-
Fatal error: Call to a member function load_content() on a non-object in E:\Xampp\htdocs\firecms\application\modules\sidebar_login_box\controllers\sidebar_login_box.php on line 7
The undefined "load_content()" function will be explained further down (in Sidebar Controller).
The Error lines
MX/Loader
/*Line 140*/if (isset($this->_ci_classes[$class]) AND $_alias = $this->_ci_classes[$class])
/*Line 141*/ return CI::$APP->$_alias;
MX/Controller
/*Line 56*/public function __get($class) {
/*Line 57*/ return CI::$APP->$class;
How I tried to load the modules
This was my first attempt (loading the file and instancing its class):
class Template {
//[...]
public function load_sidebars()
{
$sidebars = $this->CI->cms_model->get_sidebars();
foreach ($sidebars as $sidebar)
{
if (trim($sidebar["content"]) == "")
{
//An example of sidebar module name is "sidebar:login_box"
//The function below changes the name to "sidebar_login_box" (the
//module's folder and controller name.
$module = str_replace(':', '_', $sidebar["module"]);
$file_path = APPPATH.'modules/'.$module.'/controllers/'.$module.'.php';
require_once $file_path;
$class = ucfirst($module);
$object = new $class();
$module_data = $object->index();
$this->_section_data["sidebars"][]["content"] = $module_data;
}
else
{
$this->_section_data["sidebars"][]["content"] = $sidebar["content"];
}
}
}
//[...]
}
And this was my second attempt (using the loader function):
public function load_sidebars()
{
$sidebars = $this->CI->cms_model->get_sidebars();
foreach ($sidebars as $sidebar)
{
if (trim($sidebar["content"]) == "")
{
$module = str_replace(':', '_', $sidebar["module"]);
$this->CI->load->module($module);
$module_data = $this->CI->$module->index();
$this->_section_data["sidebars"][]["content"] = $module_data;
}
else
{
$this->_section_data["sidebars"][]["content"] = $sidebar["content"];
}
}
}
The sidebar controller
This is how the sidebar controller looks like:
class Sidebar_login_box extends Fire_Controller {
public function index()
{
$view_data = array();
//The load_content function in the template library is used to parse template files
//and return them as a string.
return $this->template->load_content("login_box", $view_data);
}
}
The Fire Controller
The Fire_Controller is my core controller. My core classes' prefix is Fire_ instead of MY_.
This is how the fire controller looks like:
class Fire_Controller extends MX_Controller {
public function __construct()
{
parent::__construct();
//Load configurations from the database.
$this->config->load_db_configs();
//Set the timezone.
date_default_timezone_set(config_item("timezone"));
//Loads the form validation library.
$this->load->library("form_validation");
//Reset the Form Validation CI Object (to fix problems with HMVC CI).
$this->form_validation->CI =& $this;
//To reduce load time, the template library will not be loaded in ajax
//requests.
if ( ! $this->input->is_ajax_request())
{
$this->load->library("template");
}
//Force access via SSL connection (HTTPS) if necessary.
if ((int)config_item('force_https') === 1)
{
force_https();
}
}
Note: This is a very recent project of mine, which means that the framework and all third party extensions are in the most recent stable version as of January 06, 2015.
Thank you for your time,
Best regards.
Fixed.
The sidebars were loaded from the set_defaults() method, which was called by the constructor method in my template library. And since it wasn't fully loaded, the template object was not saved in CI's super object, thus being inaccessible and throwing the errors in the sidebar module.
I have moved the set_defaults() call to the render_page() function of my template library (which are called by the modules' controllers), and now it's working perfectly.
Too bad I added bounty a few hours before finding the solution, hehe.
You need to load the library before you can use it in the sidebar controller. It isn't being passed from the parent. Try this:
class Sidebar_login_box extends Fire_Controller {
public function index()
{
$view_data = array();
$this->load->library('template');
//The load_content function in the template library is used to parse template files
//and return them as a string.
return $this->template->load_content("login_box", $view_data);
}
}
Cheers!

Fatal error: Class 'Zend_Log' not found

I'm getting the following error in magento administration
Fatal error: Class 'Zend_Log' not found in /home/website/public_html/app/code/community/Uni/Fileuploader/Block/Adminhtml/Fileuploader/Edit/Tab/Products.php on line 241
This is a community extension, which has been working fine on my website. The error makes no sense to me, because the line 241 contains just a closing "}" character.
class Uni_Fileuploader_Block_Adminhtml_Fileuploader_Edit_Tab_Products extends Mage_Adminhtml_Block_Widget_Grid {
...
...
...
public function getRowUrl() {
return '#';
}
public function getGridUrl() {
return $this->getUrl('*/*/productgrid', array('_current' => true));
}
protected function getFileuploaderData() {
return Mage::registry('fileuploader_data');
}
protected function _getSelectedProducts() {
$products = $this->getRequest()->getPost('selected_products');
if (is_null($products)) {
$products = explode(',', $this->getFileuploaderData()->getProductIds());
return (sizeof($products) > 0 ? $products : 0);
}
return $products;
}
} // line 241, where error occurs
I can post the rest of the code, if you need it.
I noticed that if I upgrade to PHP 5.4 version the error disappears, but since 5.4 version causes other errors on my website, I have to continue using 5.3.
Any ideas on how to solve this?
The problem could be the name of one of the methods in your custom class.
Take for example the method name is getData() ,
Try searching for generic method names in your script, such as getData, which might be reserved by some of Magento’s core classes. I figure that these methods have predefined functionality, which your module is missing support for, and Zend then tries to write an exception to Zend log.
Reference link: netismine
I got the same error when rewriting a payment method.
public function authorize($payment, $amount)
Solved rewriting exactly the same main method:
public function authorize(Varien_Object $payment, $amount)
Magento 1.9.1.0/PHP 5.5

Asset Library not loading correctly

I am trying to implement the CI Asset manager found here. After I placed the files in the correct locations and then tried to call the assets in my main view I get the following error
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$assets
Filename: index/index.php
Line Number: 18
What am I forgetting to do that is causing this error?
Line 16-18 are
$this->load->library("Assets");
echo $this->assets->load("ie10mobile.css", "Content");
You have to load library and use it in controller file, not the view.
Sample controller function:
function index()
{
$this->load->library("assets");
$this->data['css'] = array(
$this->assets->load("ie10mobile.css", "Content"),
$this->assets->load("style.css", "Content"),
$this->assets->load("custom.css", "Content")
);
$this->load->view('index_view', $this->data);
}
Sample view file: index_view.php
foreach ($css as file) {
echo $file;
}

Categories