Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 气体点火器_Php_Codeigniter_Orm - Fatal编程技术网

Php 气体点火器

Php 气体点火器,php,codeigniter,orm,Php,Codeigniter,Orm,我是Gas ORM新手,我有两个表角色和用户,一个用户只有一个角色 如何在用户视图中显示角色名称而不是角色id。我正在使用气体ORM和codeigniter 榜样 function _init() { self::$relationships = array( 'user' => ORM::has_many('\\Model\\User_model'), ); self:

我是Gas ORM新手,我有两个表角色和用户,一个用户只有一个角色 如何在用户视图中显示角色名称而不是角色id。我正在使用气体ORM和codeigniter

榜样

    function _init()
{
    self::$relationships = array(
                            'user' => ORM::has_many('\\Model\\User_model'),
                    );
    self::$fields = array('role_id' => ORM::field('auto[11]'),
                           'name' => ORM::field('char[255]', array('required','max_length[255]')),);
            }
function _init()
        {
                self::$relationships = array(
                        'role' => ORM::belongs_to('\\Model\\Role_model'),
                );
                self::$fields = array(
                        'user_id'                    =>           ORM::field('auto[255]'),
                        'email'                    =>             ORM::field('email[255]'),
                        'name'                    =>              ORM::field('char[255]'),
                        'username'                 =>             ORM::field('char[255]', array('required','max_length[255]')),
                        'password'              =>                ORM::field('char[255]'),
                        'active'                 =>              ORM::field('numeric[255]'),
                );
        }
用户模型

    function _init()
{
    self::$relationships = array(
                            'user' => ORM::has_many('\\Model\\User_model'),
                    );
    self::$fields = array('role_id' => ORM::field('auto[11]'),
                           'name' => ORM::field('char[255]', array('required','max_length[255]')),);
            }
function _init()
        {
                self::$relationships = array(
                        'role' => ORM::belongs_to('\\Model\\Role_model'),
                );
                self::$fields = array(
                        'user_id'                    =>           ORM::field('auto[255]'),
                        'email'                    =>             ORM::field('email[255]'),
                        'name'                    =>              ORM::field('char[255]'),
                        'username'                 =>             ORM::field('char[255]', array('required','max_length[255]')),
                        'password'              =>                ORM::field('char[255]'),
                        'active'                 =>              ORM::field('numeric[255]'),
                );
        }
在我的视图中我将用户显示为

<?php $row_count = 0; foreach ($users as $user){ $row_count = ++$row_count;?>
                  <tr>
                    <td><?php echo $row_count; ?></td>
                    <td><?php echo $user->role_id . " " . $user->name; ?></td>
                    <td><?php echo $user->username; ?></td>
                    <td><?php echo $user->role($user->role_id)->name; ?></td>
                    <td><?php if($user->active == 1) echo "Active"; else echo "Inactive"; ?></td>
                    <td><span class="btn btn-warning btn-sm" data-toggle="modal" data-target="#editUser" onclick="edit('<?php echo $user->user_id; ?>')"><span class="glyphicon glyphicon-pencil"></span>&nbsp;Edit</span>
                      <a href="javascript:void(0);" onclick="rm('<?php echo $user->name; ?>','<?php echo $user->user_id; ?>');"><span class="btn btn-danger btn-sm"><span class="glyphicon glyphicon-trash"></span>&nbsp;Delete</span></a>
                    </td>
                  </tr>
                    <?php } ?>


我对此也有同样的问题

如果使用主键设置,请尝试此操作

orm.php

    /* We wanna use foreign_key always.
    if (empty($this->primary_key))
    {
    */
        if ( ! empty($this->foreign_key))
        {
            // Validate foreign keys for consistency naming convention recognizer
            $foreign_key = array();

            foreach($this->foreign_key as $namespace => $fk)
            {
                $foreign_key[strtolower($namespace)] = $fk;
            }

            $this->foreign_key = $foreign_key;
        }
        else
        {
            // If so far we didnt have any keys yet, 
            // then hopefully someone is really follow Gas convention
            // while he define his entity relationship (yes, YOU!)
            foreach ($this->meta->get('entities') as $name => $entity)
            {
                if ($entity['type'] == 'belongs_to')
                {
                    $child_name     = $entity['child'];
                    $child_instance = new $child_name;
                    $child_table    = $child_instance->table;
                    $child_key      = $child_instance->primary_key;

                    $this->foreign_key[strtolower($child_name)] = $child_table.'_'.$child_key;
                }
            }
        }
    //}

我对此也有同样的问题

如果使用主键设置,请尝试此操作

orm.php

    /* We wanna use foreign_key always.
    if (empty($this->primary_key))
    {
    */
        if ( ! empty($this->foreign_key))
        {
            // Validate foreign keys for consistency naming convention recognizer
            $foreign_key = array();

            foreach($this->foreign_key as $namespace => $fk)
            {
                $foreign_key[strtolower($namespace)] = $fk;
            }

            $this->foreign_key = $foreign_key;
        }
        else
        {
            // If so far we didnt have any keys yet, 
            // then hopefully someone is really follow Gas convention
            // while he define his entity relationship (yes, YOU!)
            foreach ($this->meta->get('entities') as $name => $entity)
            {
                if ($entity['type'] == 'belongs_to')
                {
                    $child_name     = $entity['child'];
                    $child_instance = new $child_name;
                    $child_table    = $child_instance->table;
                    $child_key      = $child_instance->primary_key;

                    $this->foreign_key[strtolower($child_name)] = $child_table.'_'.$child_key;
                }
            }
        }
    //}

这里有一个更好的答案。这里有一个更好的答案。