Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthorupupnaway
    • CommentTimeNov 17th 2007 edited
     
    I'm trying to translate a RoR tutorial to Akelos, but am having a hard time with PHP's implementation of class methods. In ruby, you simply use the "self." before the method name. How would the code below translate to Akelos and PHP5?

    ruby code:

    (in controller)

    class StoreController < ApplicationController

    def index
    @products = Product.find_products_for_sale
    end

    end


    this calls a method in the Product model--find_products_for_sale.

    (in model)

    class Product < ActiveRecord::Base

    def self.find_products_for_sale
    find(:all, :order => "title")
    end

    end


    The method is defined as a class method. But in PHP I need to use "static" keyword?
    Any help would be appreciated. Thanks
    • CommentAuthorKaste
    • CommentTimeNov 17th 2007
     

    There is a huge difference between class-methods in ruby and static-methods in PHP I dont wanna discuss here.

    Anyway your example is very easy:

    function index()
    {
        $this->products =& $this->Product->findProductsForSale();
    }
    
    function findProductsForSale()
    {
        return $this->find([...]);
    }
    
Add your comments
    Username Password
  • Format comments as