Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Another Underscore Name Question
  • Alright, I must be missing something here. I have a module called "cms".
    I have these files:
    cms/classes/model/page.php -- Model_Page
    cms/classes/model/pages/template.php -- Model_Pages_Template
    

    But when I try to reference Template from Page, I get an error:
    Related model not found by Belongs_To relation "template": Model_Pages_Template

    With this code in Model_Page:
    protected static $_belongs_to = array(
         'template' => array(
          'key_from' => 'id',
          'model_to' => 'Model_Pages_Template',
          'key_to' => 'page_id',
          'cascade_save' => true,
          'cascade_delete' => false,
      )
        );
    

    I've read loads of posts on underscores meaning folders.. so what am I doing wrong? :: Update ::
    If I add \\Cms\\ in front of the class, it suddenly works.. but they are all in the CMS namespace already and I've never had to do this before.
    protected static $_belongs_to = array(
         'template' => array(
          'key_from' => 'id',
          'model_to' => '\\Cms\\Model_Pages_Template',
          'key_to' => 'page_id',
          'cascade_save' => true,
          'cascade_delete' => false,
      )
        );
    
  • Classnames in strings are always global, as you found out you always have to specificy the full namespace.

Howdy, Stranger!

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

In this Discussion