Third-party library not loading in Expression Engine 2.0 - php

I'm developing a properties module for Expression Engine that's to take properties from Rightmove's BLM format and populate a database, and then those properties be searchable from the front-end.
I've found a CodeIgniter library (http://biostall.com/codeigniter-rightmove-blm-parser-library) that does the heavy lifting of the BLM files. However, I can't seem to load it.
My code in mcp.properties.php looks like this:
$config = array();
$this->EE->load->library('rightmove_v3_parser');
$this->rightmove_v3_parser->initialize($config);
$data['properties'] = $this->rightmove_v3_parser->process();
print '<pre>'; print_r($data['properties']); print '</pre>';
exit;
The library files are in a libraries sub-folder in my properties add-on folder under /system/expressionengine/third_party/.
However, when using the above code, I get the following error in Expression Engine:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Properties_mcp::$Rightmove_v3_parser
Filename: properties/mcp.properties.php
Line Number: 44
Fatal error: Call to a member function initialize() on a non-object in /Users/Martin/Sites/expressionengine/system/expressionengine/third_party/properties/mcp.properties.php on line 4
Where am I going wrong? Why can't I bundle this library with my add-on and call it within my add-on?

You've missed the EE object when referencing the library. So after loading the library you should use
$this->EE->rightmove_v3_parser
to access it, rather than
$this->rightmove_v3_parser

Have you included the library at the top of your plugin, i could be wrong but I don't think loading a library like that will work from a library subdir in your third_party plugin folder. Try including the library at the top of your plugin.

Related

What is the correct way to include PHP functions in Joomla for use in articles?

I am using Joomla 2.5 and DirectPHP. I can run PHP code in an article just fine. I would like to include a library of PHP functions to be available for use in all articles. What is the best way to include the function library?
I tried including (with require) from the template's index.php and even putting the functions directly in index.php, as suggested here. None of the functions are defined in the article. A test with variables and global variables also finds them undefined in the article.
I then created a custom HTML module with the PHP functions that I then used in my template, but they are still undefined in the article. Oddly enough, if I try and declare the function again in the article I get "Cannot redeclare...". How can the function be both undefined, not re-defineable?
I also tried using a namespace to define and use my functions. Same result.
Code in my custom html module:
<?php
namespace c6;
function testit5()
{
echo "hello world 5";
}
?>
Code in my article:
<?php
namespace c6;
testit5();
?>
Result:
Fatal error: Call to undefined function c6\testit5() in /home/testsite/www/www/c6test/plugins/content/DirectPHP/DirectPHP.php(58) : eval()'d code on line 5
go to,
Login to admin -> Extensions Menu -> Module Manager -> Create New Module -> Choose Custom HTML
and create you own module and add php functions.
I figured it out! My problem was the order Joomla processes things. Apparently the article is processed first, then the template. So my code using the function executed before the module that defined the function was executed. (When I got the "cannot redeclare" error, it was coming from the template, not the article.) I moved my loadposition from the template to the article and it works.

CakePHP: Fatal error: Call to a member function image()

I'm using the following Helper: http://pastebin.com/qBs2GvG4 in my CakePHP 2.0 app to show a gravatar for a user like so:
<?php $this->Gravatar->image($profile['User']['email'], array('default'=>'mm','size'=>48)); ?>
However it gives the error:
Fatal error: Call to a member function image() on a non-object in /Users/cameron/Sites/social/app/View/Helper/GravatarHelper.php on line 97
Any ideas what the problem is? This worked in my 1.3 app so wondering if something has changed between 1.3 and 2.0 that causes this issue? Thanks
Helpers have slightly different dependencies in 2.0, especially if they require other helpers.I actually made the commits to fix this one in the CakeDC utils plugin.
You can find an updated version of that helper here: https://github.com/CakeDC/utils/blob/2.0/View/Helper/GravatarHelper.php
Looks like the GravatarHelper has a dependency on the HtmlHelper. Is Html in your list of helpers in the controller?

call to undefined function View::fetch cakePHP

I started experimenting with CakePHP version 2.x, I created a default.ctp layout file in View/Layouts inside of which I have codes like:
echo $this->fetch('css');
but I keep getting the following error:
Fatal error: Call to undefined method View::fetch() in C:\wamp\www\.......
I tried creating a block for this css in my view file like:
$this->start('css');
$this->Html->css('home_page', null, array('inline' => false));
$this->end();
But when I do this I get the following error:
Fatal error: Call to undefined method View::start() in C:\wamp\www\.......
Any help please?!!!
Thank you
View::fetch() is available since 2.1, what is your version?
I dont think you need fetch, start, end for including css, you can just use:
$this->Html->css(array('home_page.css'));
//OR
echo $this->fetch('css'); //from version 2.1
Ref: Css CakePHP
The book is a little ahead of the release atm! fetch() is from 2.1 code, which is still alpha.
Try generating a default layout using cake's bake tool and study that to see how 2.0 does it, and make sure do you don't follow bits of the book which say they are new in 2.1 until you are using the 2.1 codebase.

Connecting to the database in a Created Library - CodeIgniter

I have a little issue right now and its bugging me, hopefully one of you guys will be able to help me out.
Basically I'm creating a library to use in CodeIgniter and I'm getting this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Functions::$db
Filename: libraries/Functions.php
Line Number: 11
The Database library is already on autoload aswell as my functions library:
$autoload['libraries'] = array('database','session','encrypt','functions');
The Functions.php file is located in the application/libraries folder accordingly.
Line number 11 consists of this:
$this->db->where('username', $data);
Not sure as to why the db is an undefined property?
It's probably because you need to get the CI instance first since not everything is loaded yet:
$ci =& get_instance();
$ci->db->where('username', $data);
See if that helps. Also see the instructions here.

PasswordHash not working with CodeIgniter

I have put the files I downloaded from http://www.openwall.com/phpass/ to application/libraries
In my controller, I am using this code -
$params = array(
'phpass_hash_strength' => 8,
'phpass_hash_portable' => FALSE
);
$this->load->library('PasswordHash', $params);
$password = $this->passwordhash->HashPassword($pwd);
I am getting these errors -
A PHP Error was encountered
Severity: Notice
Message: Uninitialized string offset: 3
Filename: libraries/PasswordHash.php
Line Number: 116
A PHP Error was encountered
Severity: Warning
Message: strpos() [function.strpos]: Empty delimiter
Filename: libraries/PasswordHash.php
Line Number: 116
Update
Removed PasswordHash.php, using SimpleLoginSecure now.
I had the same issue whilst integrating PasswordHash into Symfony2.
To solve it, I renamed the PasswordHash method to __construct.
In theory, PHP 5+ should look for a method with the same name as the class if it can't find a constructor (http://php.net/manual/en/language.oop5.decon.php). My guess is that the class name resolves differently once a namespace is added (a requirement for my integration), but I've not investigated at all.
I think your problem is you are trying to use a generic PHP object as a CodeIgniter library. You can't just do that. You'll need to modify the original code to work, or download one of the contributed libraries already designed for CodeIgniter.
CodeIgniter libraries have some restrictions (such as how they are instantiated), so just dropping any file into the libraries folder won't work.

Categories