Tuesday, September 6, 2011

Re: Convert native PHP class into cakePHP component

I think it's better not to change a pre-built class (in case they perform updates to it or fix any bugs you wouldn't be able to make use of them).

This is why CakePHP has the "vendors" system.  You simply place your pre-built class in your vendors folder and call it from your application. For example:

App::import('Vendor','SmsPHP'); 
$sms_php=new SmsPHP();

What I would also do is create a component that simply interacts with this class.
For example create a component called SmsCakeComponent, and inside the component import the class from vendors and call it's functions.
The reason why I'd create a component would be to abstract the vendor class away from my application, in that case if I want to switch classes I would only need to fix my component instead of fixing the entire application, therefore making my component act as an "interface" between my application and the vendor class.

I hope I wasn't very confusing  :)

Anyway, here's a link from the CakePHP book that might help you get started with vendors: http://book.cakephp.org/view/943/Loading-Vendor-Files

Teddy

On Tue, Sep 6, 2011 at 9:03 AM, elogic <asymonds@elogicmedia.com.au> wrote:
Hi All,

I am only new to cakePHP and am learning slowly (but loving it). I
have been given a pre-built class and some basic instructions on how
to use it from our SMS provider (it works very well and easily with
native PHP).

I need to convert the class into something that I can easily use
within cakePHP sites. Am I right in assuming I want to convert it into
a component? If not what would you suggest?

Are there any tutorials around that might help me complete my task? I
presume it shouldn't be too hard at all once I know what I am doing.

Thanks

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: