Question

When i use FuelPHP ORM to get ALL results using find('all'), it's return only one record.

This is my db. table name ws_config. (no primary key)

--------------------------
config_name | config_value |
--------------------------
site_name | My Site |
--------------------------
member_allow_register | 1 |
--------------------------

This is my model.

class Model_Config extends Orm\Model 
{
    protected static $_table_name = 'config';
    protected static $_primary_key = array();// no PK, need to set PK to empty array.
}

This is my controller

class Controller_Account_Register extends \Controller_Basecontroller 
{
    public function action_index() 
    {
        $config = Model_Config::find('all');
        $output['config'] = $config;

        // call function below is in base controller. it is just load theme (this view page into main template) nothing special.
        return $this->generatePage('front/templates/account/register_v', $output);
    }
}

This is my view file.

foreach ($config as $row) {
    //print_r($row);
    echo $row->config_name;
    echo ' = ';
    echo $row->config_value;
    echo '<br>';
}

The result is just

site_name = My Site

How to get ALL results from this database table? or How to get multiple results upon where ondition?

Was it helpful?

Solution

The issue here is that indeed as @vee says the ORM expects you to have a primary key assigned to your table. By default in the orm this is simply a column called "id". If you do not specify a PK unexpected behaviour happens, such as this.

Once you define a primary key on your table this issue should be resolved.

The simplest thing would be to just add an auto-incrementing ID column as this is the default for orm models.

OTHER TIPS

FuelPHP ORM needs Primary key to get ALL results.

No PK you can get only one result.

erm... :(

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top