Jump to:

23457 Posts in 18905 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » How to create php class for only

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1815 Views
  • biapar
    Avatar
    Forum Moderator
    435 Posts

    How to create php class for only Link to this post

    Hi,

    What are steps to create a class for only update database ?
    That is: I've a product class with some options. Then, after some action, a remote webservice return data on my site ( like PayPal IPN ) and I've update products info.
    And How will be link for call that action?

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: How to create php class for only Link to this post

    Well if you want a blank php class then in SS you can do exactly as you do in standard php, simply don't extend page

    <?php

    class MyClass {

    function foo() {
    // update db you can use DB::query(), DataObject::get()...
    }
    }

    ?>

    And if thats in your mysite folder you can simply to this in any other function / class in your project you can do

    $var = new MyClass();
    $var->foo();

    Nothing fancy their, just standard PHP OOP. If you provide more specific information about what you want to do we may be able to help further.

  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: How to create php class for only Link to this post

    Yes, I know.
    But I wish to update fields of "product" that "product" is a SS class that extend page or
    Do I made "Product" class as dataobject?

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: How to create php class for only Link to this post

    Do I made "Product" class as dataobject?

    Just to be clear, your "product" is not referring the the product class that is bundled with ecommerce? if it is you should have this in the ecommerce forum.

    If your building your own Product class the option of extending Page or Dataobject depends on what you want. Do you want each product to have a page on the site? Do you want to manage products in the sitetree? If these are yes then extend Page, otherwise extend DataObject.

  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: How to create php class for only Link to this post

    I don't use ecommerce module. I need a simple simple cart. I simulate cart with simplejs javascript.

    I need product to manage a Wedding-wishlist.
    I simulated a list as a Product Categorie and each product with a page child of Categories.
    After a person books a gift and payed via PayPal, I need to setup booked flag at true value. So, that product is not more in list.
    So, I need a method to read returned value from PayPal.

    1815 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.