Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7986153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:46:10+00:00 2026-06-04T11:46:10+00:00

I cannot access joined table with PHPActiveRecord/Twig. Here is simplified code. It has two

  • 0

I cannot access joined table with PHPActiveRecord/Twig. Here is simplified code. It has two models (Code and User), and each code belongs to one user, so I want to list codes with the name of code’s author.

php

// model
class Code extends ActiveRecord\Model {
    static $belongs_to = array(
        array('user'),
    );
}

class User extends ActiveRecord\Model {
    static $has_many = array(
        array('code'),
    );
}


// controller
$codes = Code::all(array('include' => 'user'));
var_dump($codes);      //-> successfully displayed codes list and their authors

$this->twig->display('codelist.twig', $codes);

template.twig

{% for code in codes %}
{{ code.name }}        //-> successfully displayed code's name
{{ code.user.name }}   //-> failed to output user's name with error
{% endfor %}
// error:
// An exception has been thrown during the rendering of a template ("Call to undefined method: user") in "inc/template.twig" at line **.

I saw this page:
http://twig.sensiolabs.org/doc/templates.html

Implementation

For convenience sake foo.bar does the following things on the PHP
layer:

check if foo is an array and bar a valid element; if not, and if foo
is an object, check that bar is a valid property; if not, and if foo
is an object, check that bar is a valid method (even if bar is the
constructor – use __construct() instead); if not, and if foo is an
object, check that getBar is a valid method; if not, and if foo is an
object, check that isBar is a valid method; if not, return a null
value. foo[‘bar’] on the other hand only works with PHP arrays:

check if foo is an array and bar a valid element; if not, return a
null value.

Although I can access user attribute via $codes[0]->user, why can’t I access user attribute in twig templates file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:46:11+00:00Added an answer on June 4, 2026 at 11:46 am

    Thanks to greut, I solved the problem. I replaced function __isset in lib/Model.php in PHPActiveRecord.

    /**
     * Determines if an attribute exists for this {@link Model}.
     *
     * @param string $attribute_name
     * @return boolean
     */
    public function __isset($name)
        {
            // check for getter
            if (method_exists($this, "get_$name"))
            {
                $name = "get_$name";
                $value = $this->$name();
                return $value;
            }
    
            return $this->read_attribute($name);
        }
    

    https://github.com/kla/php-activerecord/issues/156

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code does not compile, saying error C2248: 'A::getMe' : cannot access private
By default you cannot access a file that is uploaded until it has been
cannot access asp.net server side control from jquery Label <label id=lblClanName runat=server>Something here</label> Jquery
When I create a new coffeescript file, I cannot access the code in the
Results r = (Results)Page.LoadControl(Results.ascx); In my Page i cannot access USER CONTROL CLASS(Results) Gives
Here is the error: TypeError: Error #1009: Cannot access a property or method of
This code generates C2248 : 'A::B::ExceptionB' : cannot access private class declared in 'class
If the end_user cannot access the source code of the app, why we still
Here is the error: TypeError: Error #1009: Cannot access a property or method of
I cannot access http://android.git.kernel.org/ . So where can I download the source code of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.