Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Having problem with ORM
  • Hi Guys! Can someone please tell me what i'm doing wrong here? I'm getting this error message:
    Fuel\Core\Database_Exception [ 1054 ]: Unknown column 't0.id' in 'field list' [ SELECT COUNT(t0.id) AS count_result FROM `users` AS `t0` WHERE `t0`.`username` = 'wwwe' ] /classes/model/user.php
    <?php
    
    class Model_User extends \Orm\Model {
    
        protected static $_primary_key = array('user_id');
        protected static $_properties = array('user_id', 'username');
    
    }
    

    classes/controller/user.php
    <?php
    
    Class Controller_Users extends \Controller_Base_Public {
    
        public function before() {
            parent::before();
        }
       public function action_check() {
            $query = Model_User::find()->where('username', 'wwwe');
            $total = $query->count();
            echo $total;
        }
    }
    

    Also, when using controller_template how do i echo something to the browser without the template files? Basically I want to call a method with ajax call within controller_template like:
    public function ajax_check(){
    echo 1;
    } 
    

    It complains about variables not defined in defined in the template file. Please help. Thanks
  • If you're not using the template the Controller_Template might not be the best option, but if you do need to switch off the auto rendering that's possible. After the following code the template won't be rendered anymore:
    $this->auto_render = false;
    
    Any output should not be echo'ed though, add it to $this->response->body from your controller. I also think I know what causes your Orm problem, for now this will probably solve it:
    $query->count('user_id');
    
    Can you make a bugreport out of it on Github?
This discussion has been closed.
All Discussions

Howdy, Stranger!

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

In this Discussion