I’m trying to write my first extension (bad news: I’m no programmer – good news: it’s a simple one).
What I want the extension to do is rewrite the basepath for pagination links so that they takes the basepath I’ve specified in the extension rather than taking the basepath determined by the current URI.
I’m doing something similar to the subject in this thread: http://ellislab.com/forums/viewthread/52552/
I’ve got the extension loaded and enabled, but I don’t know exactly where to set the new basepath in the code. I don’t know if I’ve even GOT the right code in the extension.
What’s more, I get this error when I call the extension in my template:
Notice: Undefined property: paginate in /home/pmh1450/public_html/ee/extensions/ext.categories_pagination.php on line 46
My extension file is attached. I’ve simply copied the code that seems to do the work in the mod.weblog.php file, where the docs tell me to look.
How/where do I set the variable for the specific basepath I want the links to use?
Any help would be GREATLY appreciated.
$this is a reference to a class’s “self” so inside the Weblog class, it’s referring to the Weblog class; inside your extension it’s referring to the Categories_pagination class, which is why it’s coming up as not defined. The extension provides you with access to the Weblog class’s $this object:
$edata = $EXT->universal_call_extension('weblog_module_create_pagination', $this);
But the method in your extension doesn’t have the right arguments:
function pagination_basepath_rewrite($count = 0, $query = '')
It should accept only one argument, as that’s all the hook is sending. You can name it whatever you like, such as:
function pagination_basepath_rewrite(&$WBLG)
And then you can change all of the code’s references of $this to $WBLG. The & in front of it instructs PHP to take the argument by reference, which means instead of working on a copy of the Weblog class object, you will be able to modify it directly.
Thanks for the reply, Derek. Following your cues, I made the suggested changes to the code only to activate the plugin and have the following errors display on any page in the site where pagination appears.
Notice: Undefined variable: count in /home/pmh1450/public_html/ee/extensions/ext.categories_pagination.php on line 78
Notice: Undefined variable: count in /home/pmh1450/public_html/ee/extensions/ext.categories_pagination.php on line 84
Of course, I only want the extension to be used on one single page, the one that I’m pulling in with AJAX.
I think I’m very far away from understanding the consequences of poking the code to make an attempt at this now…
Much appreciated.
That error means pretty much what it says; you are referencing a variable named $count that hasn’t been defined. And I agree, you probably want to start learning PHP with simpler code, and probably not with an extension as it requires not only sufficient PHP skill but above average understanding of the code surrounding the hook; for this particular goal you would probably benefit from hiring a PHP developer to handle the task.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.