Creating a Codeigniter Library - php

bit of a theory question this one. I would like to write my own library for codeigniter. It's going to be from connecting to different british Accountancy packages via API's. If it were a single package I was writing it for then I could create the library easily, however, it will be multiple. I intend to load the library as follows:
$params = array('package' => 'quickbooks');
$this->load->library('accountancy', $params);
Through my research so far, each API does not offer the same functionality therefore my library will have to be able to disable/enable functions based on the selected package. Also, the api's are different so each function will have to work differently based on the selected package also.
Firstly, is a library the best course of action?
Does anyone have any tutorials they can point me to or anything else to help?
Not looking for someone else to write it for me, just looking to be pointed in the right direction.
Thanks

There are probably multiple solutions.
If what you need to accomplish can be conceived as an abstraction layer (which means that, regardless of which accounting package you're using, you use the same functions to get things done) then using the "Drivers" approach might work.
First, check out the CI documentation for Using CodeIgniter Drivers.
CI uses the driver pattern for the cache, database and session classes. Studying that source code may prove helpful. Cache.php might be the easiest to get your head around to start with.
Via Google I found one Codeigniter Drivers Tutorial and I'm pretty sure the Stack Overflow has some info too.
Here's another example of using CI drivers.
I confess that I didn't look at either tut very closely. So I'm not certain how helpful they will be.

Related

Making joomla Extension in my own way

I've tried to understand the structure of joomla. I've read many kinds of documents and tutorial regarding about how to make extensions in joomla. I can't able to understand it fully. I still had some doubts on it. I've made a simple component in joomla by using MVC concept and using some joomla core files. I won't say that it is like same as what professional are making it. I've used 30% of joomla like using MVC concept, extending the core files of joomla and connected with the database using joomla syntax and some other ways also. Rest of the percent, i've used my own codes by using oops concept. So do you think that is it good enough to make an extension like this or i have to make an extension like that or i really have to learn and understand the official joomla way of making it's extension. I want to know it please.
First of all the joomla is given a brief details for developing its extensions.
You can check the following url for understanding the components structure of joomla.
http://docs.joomla.org/Developing_a_Model-View-Controller_Component/1.5/Introduction
In this doc at the end you can find a download link download the component and go through the code you will get full idea about joomla MVC concept.Its pretty simple.
I think no one can explain your requirement with what you are expecting.
Just keep this in mind while developing joomla's extensions.
1)Do not edit core file for your component task achievement.
2)Try to use jRequest class for getting submitted values.
3)For new task use your controller overrided functions.
4)Make all your sql queries inside model only.
5)And make an extension that compact able for later version too.
These are the tips i can give you.
Just walk through the code of some good extensions and try to follow that .
Hope this may help you..
For ease of maintenance and for future development I would definitely recommend that you develop your component the right way. If you are going to release the component I would say that it is a requirement.
The who MVC structure can be confusing at first but once you get your head around it is really nice.
I would suggest making the MVC skeleton by using the Joomla Component Creator
http://www.notwebdesign.com/joomla-component-creator/ and then add the custom code yourself.

PHP class for use with Google Analytics API

I want to find a PHP class or framework to get data from the Google Analytics API.
I've already used gapi, which is great but it has never been updated since 2009 and it lacks new features from the API such as segments.
Can you please share the classes you've used and their key features ?
Thank you
Edit: I did find an experimental implementation of segments in issue 28 for the repository.
You mentioned gapi already but it seems to be the standard as far as a PHP library for Google Analytics goes. You may find fresher classes on GitHub with your needed functionality.
I took a look around and it seems that your best option is to fork an existing class such as gapi and add the functionality to it which is not what you wanted to hear. I recommend taking a look around at the Google supported libraries for clues on how they implemented the features you want.
This is a good opportunity for you to contribute to an open-source project. Even though this code was last changed in 2009, it's fairly short and can be easily customized to do what you want as long as the corresponding API functionality is there.
Try using the Query Explorer to see what's available. It looks like it will help you build segment queries too.

PHP framework of intermediate complexity, in between CodeIgniter and Yii?

Something easy like CI (this means mandatory good, easy, up to date documentation). But also with some more features than CI.
Yii has lots of features, but it is also more complex (and it kind of forces you to have to use lots of it features). That means adding some functionality to your web-app takes three times as long because you have to figure out lots of new small functionalities of Yii.
It's kind of like the CI "gets out of your way" when it needs to, and Yii gets in your way, and if you don't do it its way, it breaks.
Features missing in CI that would be nice to have in this new "intermediate" PHP framework:
Code generation (crud).
Authentication.
Access control.
Layouts.
Widgets.
Easyer / automated pagination (like yii)
easy uri parameters
Where Yii causes me problems:
It's like for every small task there is some inbuilt functionality (this is good), but, YOU HAVE to use the inbuilt functionality, otherwise bad things happen. (CI gets out of your way, but does it too much, Yii helps a lot, but is butting in too much at times, and it forces you to sift through its documentation so that you discover these functions without which you are not able to accomplish a task that would take four time less, in CI, or in a non framework app).
Is there something in between ?
(ASP.NET MVC could be 'it', but I don't know the language, so the effort to learn it would be greater than learning Yii php framework really well, so I am looking for a PHP Framework)
I am a fan of CakePHP. I feel it has the specs you provided. If you want something more cutting edge you can take a look at Lithium
I have found some resources that kindof solve the problem, because they contain examples (Milan Babuškov's sugestion helped focus on "the solution").
Yii playground - examples
Yii cookbook - examples
Yii blog tutorial - more examples
PS. there is also google - I find solution (and examples) the fastest this way - ex: implement + pagination + yii
I've used both CI and Yii (on my own projects if that makes any difference). CI was my first introduction to MVC, and I found it easy going because it let me use any crappy structure and code. I wrote two full sites in CI (www.insolvencynews.com and www.thebigeat.com if you want to see complexity.)
I had a look at CakePHP but got NOWHERE.
Then I moved on to Yii and, like you, I found it pretty tough and rigid. But I then found that it was so powerful and extensible that I was so much more efficient. When I needed to add a few new features to the old CI sites, it was faster to rewrite the entire sites on Yii than to code up the extra features in CI.
I can't recommend a framework in the middle, but I can recommend sticking with Yii. When you say Yii gets in the way, can you give an example? Looking at DB stuff (in ascending order of dependence on Yii):
you can code using PHP's core MySQL functions.
$result = mysql_query($sql);
you can use Yii's DB abstraction layer.
Yii::app()->db->createCommand($sql)->queryAll();
You can use Yii's ActiveRecord:
Takeaway::model()->findAll();
you could try kohana (especially coming from ci)
You should check out the CI community, some of those extensions maybe have been written by someone else (I remember seeing Authentication and Components/Widgets somewhere)
Symfony is worth checking out. I personally don't like it much because they chose Prototype over jQuery for their ajax features, which is really annoying to use when you're used to jQuery.
Lithium might be good to check out too. However, it is php 5.3 only and you need to be really careful that this version of PHP is going to be supported on the server the site will be deployed on.
See this list for good comparisson:
http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks#PHP_2
From a personal point of view, I would go with symfony because of it's
rich features and
great integration with many other already bundeled components (Doctrine, Swift Mailer,..),
good (but at first complex) code generation that produces realy useable code to get you startet quickly,
powerfull use of templating (that will be the point you mention under "layouts)
many different, powerfull plug-ins, including Authentication & Access Control (it also has a plug-in to get jQuery support)
one of the best tutorials that I've seen with a framework
Downside is a
more complex structure,
IMO wired file structure,
a rather messy API documentaion compared to the tutorial
CodeIgniter is a nice framework if you don't want to create big apps but it lacks a great database integretaion and you already mentioned code generation.
im very good in Raw PHP, where the project at hand became too much to handle i decided to move to zend, with too too much complexity i finally moved to YII which really reduced the cost and overhead time for project development and most importantly for me is the simple integration of jquery, widget and advanced-OOP.
You could have a look at Qcodo / Qcubed.
They are both easy to pick up and offer code generation / ORM
Easy way to create forms in an mvc kind of way.
For what its worth, if you're looking for a PHP Framework that is like ASP.NET MVC then I think Prado is the closest thing you will find.

What "Attributes" can Serena Mariner's SOAP API touch in UpdateInvestment()?

I'm trying to write an interface between a home-grown project management system and Serena Mariner. (The bigwigs like to read Mariner, the worker bees like to write to the home grown system.)
How can I (programmatically?) figure out what Attribute Keys are available?
I'm actually writing the interface in PHP, but any advice would be much appreciated.
Mariner seems to have an API for working with the system. Otherwise, it might be better to ask at the Mariner Support Forum.
Update: I took a little bit more of a look at the API and it doesn't specify the attributes, which is what your question is about. I guess the support forum is the better bet then.

Class::DBI-like library for php?

I have inherited an old crusty PHP application, and I'd like to refactor it into something a little nicer to deal with, but in a gradual manner. In perl's CPAN, there is a series of classes around Class::DBI that allow you to use database rows as the basis for objects in your code, with the library generating accessor methods etc as appropriate, but also allowing you to add additional methods.
Does anyone know of something like this for PHP? Especially something that doesn't require wholesale adoption of a "framework"... bonus points if it works in PHP4 too, but to be honest, I'd love to have another reason to ditch that. :-)
It's now defunct but phpdbi is possibly worth a look. If you're willing to let go of some of your caveats (the framework one), I've found that Doctrine is a pretty neat way of accessing DBs in PHP. Worth investigating anyway.
Class::DBI is an ORM (Object Relational Mapper) for perl. Searching for "PHP ORM" on google gives some good results, including Doctrin, which I've had good luck with. I'd start there and work your way up.
I'm trying to get more feedback on my own projects, so I'll suggest my take on ORM: ORMer
Usage examples are here
You can phase it in, it doesn't require you to adopt MVC, and it requires very little setup.
The right thing to is to access the database via an abstraction layer in a way such if you change your RDBMS or how you implemented that access, you only have to modify this layer while all the rest of your application remains untouched.
To do this, to free your application from knowing how to deal with the database, your abstraction layer for DB access must be implemented by a framework such as ADODB.
All the files related to this layer must be located in a sub directory:
/ado
In this directories you'll put all of your .php.inc files which contains general methods to access the database.
How about MDB2 from pear?
It provides a common API for all
supported RDBMS. The main difference
to most other DB abstraction packages
is that MDB2 goes much further to
ensure portability.
Btw: #GaryF what are those strange title attributes your links have ? Did you add them or are they added by SO ?

Categories