Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Fuel PHP Models inside module

  • FIXED I got it, sorry for this post. It seems I had to extend Orm\Model and not \Model.
    I made some mistakes while reading the documents and confused things with one and other..
    Hi Again.. I got my modules working and want to play with FuelPHP's models.
    However I really can't get it to work, tried multiple things for however to no result. The module name is Admin and I have a model called object types:
    <?php
    
    namespace Admin;
    
    use \Orm\Model;
    
    class Model_Objecttypes extends \Model
    {
        protected static $_table_name = 'objects_types';
     
     protected static $_properties = array(
            'id', // both validation & typing observers will ignore the PK
            'name' => array(
                'data_type' => 'varchar',
                'label' => 'Name',
                'validation' => array('required'),
                'form' => array('type' => 'text'),
                'default' => 'Nieuw object',
            ),
            'slug' => array(
                'data_type' => 'varchar',
                'label' => 'Gender',
                'form' => array('type' => 'text'),
                'validation' => array('required'),
            )
        );
     
    }
    

    When using the model for example trying to get a db record in the objecttypes controller:
    <?php
    
    namespace Admin;
    
    class Controller_Objecttypes extends Controller_Base
    {
    
     /**
      * The basic welcome message
      * 
      * @access  public
      * @return  Response
      */
     public function action_index()
     {
      
      $entry = \Admin\Model_Objecttypes::find(2);
      
      var_dump($entry);
      
      // return the rendered HTML to the Request
                    return \View::forge('objecttypes/index', $this->views)->render();
     }
    
    }
    

    I receive the message: ErrorException [ Error ]: Call to undefined method Admin\Model_Objecttypes::find() Now I assumed that using an ORM (never did that before) the method "find" would be a part of the ORM which leads me to think that extending \Model failed, but if that was true I would receive an error message saying so. So my question, what am I doing wrong?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!