WEB does anyone here have experience with CakePHP or MVCs in generals?

Discussion in 'OT Technology' started by Charles, Mar 1, 2009.

  1. Charles

    Charles Andalucia, mi tierra

    Joined:
    Aug 21, 2004
    Messages:
    131,114
    Likes Received:
    77
    Location:
    Austin, T E X A S
    I'm finding myself very frustrated trying to do something that would take me 2 minutes to do if I were to just code straight php :mad:
     
  2. Charles

    Charles Andalucia, mi tierra

    Joined:
    Aug 21, 2004
    Messages:
    131,114
    Likes Received:
    77
    Location:
    Austin, T E X A S
    I have a very basic category table with id, name and parent_id.

    This controller:
    http://pastebin.com/m7884298f

    Along with this view:
    http://pastebin.com/m1b801c2

    Allow me to browse the categories which is badass on how simple cake has made it.

    but I want to get a count of the children in a specific category before it gets printed on the screen.. so that would have to be in the controller..

    This [ http://pastebin.com/m49cadafe ] 4 line function will do it, but I can't for the life of me figure out how to get to that function in the controller once I have the ID from the view..


    This is the first time I've ever used a MVC so please be gentle :o
     
  3. ge0

    ge0 New Member

    Joined:
    Oct 31, 2005
    Messages:
    8,398
    Likes Received:
    0
    Location:
    JERSEY
    yeh we are doing some things with ruby on rails at work.

    You put most of your database table method calls in your models btw.

    Like, Products table.. getProduct(product_id) would be a method in your product model.
     
  4. Charles

    Charles Andalucia, mi tierra

    Joined:
    Aug 21, 2004
    Messages:
    131,114
    Likes Received:
    77
    Location:
    Austin, T E X A S
    how the hell do I pass an id back to a model :o
     
  5. Charles

    Charles Andalucia, mi tierra

    Joined:
    Aug 21, 2004
    Messages:
    131,114
    Likes Received:
    77
    Location:
    Austin, T E X A S
    I thought maybe I needed a helper to do it.. So I made a helper with a function that should work based how it's all set up.. but I guess helpers can't access the database :dunno:
     
  6. Charles

    Charles Andalucia, mi tierra

    Joined:
    Aug 21, 2004
    Messages:
    131,114
    Likes Received:
    77
    Location:
    Austin, T E X A S
  7. ge0

    ge0 New Member

    Joined:
    Oct 31, 2005
    Messages:
    8,398
    Likes Received:
    0
    Location:
    JERSEY
    is his the equivalent of:

    1. $conditions = array('recursive' => 1, 'conditions' => array('MainCategory.parent_id' => $id), 'fields' => array('MainCategory.id', 'MainCategory.name', 'MainCategory.image_name', 'MainCategory.parent_id'), 'order' => array('MainCategory.name'), );
    of
    SELECT id, name, image_name, parent_id FROM MainCategory WHERE parent_id = $id ORDER_BY name ??


    I haven't done cake yet, but I want to..
     
  8. Charles

    Charles Andalucia, mi tierra

    Joined:
    Aug 21, 2004
    Messages:
    131,114
    Likes Received:
    77
    Location:
    Austin, T E X A S
    correct
     
  9. Charles

    Charles Andalucia, mi tierra

    Joined:
    Aug 21, 2004
    Messages:
    131,114
    Likes Received:
    77
    Location:
    Austin, T E X A S
    I tried this controller:

    http://pastebin.com/m730e807f


    With this function in the model:

    http://pastebin.com/m4fa236d3


    When I execute the controller and pass it $id I cake tells me that it's executing the query in the function (#2):
    But when i try and use set to set the 'count' variable it doesnt set it and then my view tells me that $count is undefined :mad:
     
  10. ge0

    ge0 New Member

    Joined:
    Oct 31, 2005
    Messages:
    8,398
    Likes Received:
    0
    Location:
    JERSEY
    should the model name be the table you are trying to access?
     
  11. biawokauns

    biawokauns New Member

    Joined:
    Sep 18, 2001
    Messages:
    19,893
    Likes Received:
    0
    Location:
    Republic of Kalifornia
    cake ftl, rails ftw
     
  12. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    god damn php is ugly
     

Share This Page