Welcome Guest, Not a member yet? Register   Sign In
New to CI, how to extend Libraries and helpers?
#1

[eluser]timbojones[/eluser]
Hi guys and girls,

New to CI, enjoying it and getting through much of it with topics found of this forum and in the documentation. But I've got a question:

The pagination library has a bug, where the links to "First" and "1" have trailing slashes in the URL. I know I could fix this with a .htaccess mod rewrite, but this results in an extra http request and stuff like that, seems an overkill for something that can be fixed with a simple rtrim() php function.

But, my OOP isn't crash hot, how would I go about extending the library (I don't want to hack at the core, any CI updates later would override my changes) and actually make those changes? I've managed to do it in the core, but as mentioned I don't want to do it there and am at a loss as to how to do it via a class extension. If I make my own library, extending the core library, and call it's method, wont I just end up with the resulting html string for the pagination links? (making it much harder to do the simple rtrim())?

Similar thing, but with the smiley helper. I'd much prefer to use an image sprite and css classes (reducing 40 http requests for the 40 smiley images into 1!!!). But a helper isn't a class, so is my only option here to copy the smiley file, paste it into my own helper and hack to code to suit my purposes?

Thanks, hope that all makes sense, hoping someone can point me in the right direction
#2

[eluser]WanWizard[/eluser]
See http://ellislab.com/codeigniter/user-gui...asses.html Extending core classes.

Helpers are just files with procedural functions. Just create a helper file with the same name in application/helpers, and define your own function there. It will replace the function defined in the core.
#3

[eluser]CroNiX[/eluser]
To extend core files
Creating/Extending Core Classes

Extensions to core classes go in /application/core and are prefixed with "MY_"

To modify Libraries (See "Replacing Native Libraries with Your Versions"):
Creating Libraries
Extensions to libraries go where your custom libraries go, /application/libraries

You can extend helpers the same way, but they obviously go in the /application/helpers dir.
#4

[eluser]timbojones[/eluser]
Cheers champ!

That's what I thought about the helpers! Thanks for confirming that!

Extending the core classes looks simple enough, just use the MY_ prefix instead of CI. However, that leads me to two new questions:

1. How often are core libraries like pagination "updated/tinkered" with by Ellislab? I mean, if I just replace it with my own version, I'll miss out on any updates later (there is really only one function in that library, if I override it via a class extension -> method overriding, then yeah...).
2. For the pagination, it's a really little fix for something as silly as creating urls with trailing slashes, can you report bugs, and do Ellis actually action them? (I would have thought a bug such as this would have been fixed ages ago!

Thanks, and sorry to bug you with such trivial stuff :-s
#5

[eluser]CroNiX[/eluser]
There is no definitive answer to #1. They update things as they fix bugs and add features. Take a look at the changelog to get an idea of how frequently that is. But why would you miss out on updates? You're not modifying core files. When you upgrade, you check the changelog to see if anything affects whatever you've extended and if it does, check it out and test, etc. This is normal.

Yes, you can report bugs to the GitHub repo and check out the "issues". Please search to see if it's already been fixed or reported before creating a new report. They've done a lot of work in the last 2+ years that CI 3 has been worked on getting ready for the next release, so the chances are high that it's been reported and/or fixed.

You can also check out the new unreleased version (currently, ver 3) there.
#6

[eluser]timbojones[/eluser]
Ah great, thanks for all that, much appreciated!!!




Theme © iAndrew 2016 - Forum software by © MyBB