• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
T_OBJECT_OPERATOR syntax error

#1
[eluser]CheekyGeek[/eluser]
Greetings all,
Think I've finally wrapped my head around the concepts so ready to write some code and I can't even get my index view to load without getting an error:

Here's the error message:
Code:
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /Library/WebServer/Documents/CI/system/application/controllers/user2.php on line 20

Here's line 20:
Code:
this->load->view('user_search_form');
Here's the whole controller (just started):
Code:
<?php
class User2 extends Controller
{

    function User2()
    {
        parent::Controller();
        $this->load->db();
        $this->load->model("Users_model");
        $this->load->scaffolding('users');
        $this->load->helper('url');
        $this->load->helper('form');
    }
    
    function index()
    {
        // called by default with /user2/
        //load view "user_search_form"
        // which calls /user2/search in the form action
        this->load->view('user_search_form');
    }
    
    function search()
    {
        // called with /user2/search
        // searches db table: users with various criteria from view_user_search form. Passed to
        // model: model_users "get" function
        // to populate the view "user_detail_form" (if one record is returned)
        // or populate the view "all_users" (if more than one record is returned)
        $this->load->model('Users_model');
        $data['title'] = 'User Search';
        $data['query'] = $this->Users_model->get();
    
        $this->load->view(all_users);
    }
    
    function list_all()
    {
        // called with user2/list_all
        // displays all users in a table form
        // uses model_users "get" function?
        // to populate the view: all_users
        // last td contains a link to search with user_id (calling user/search/[user_id] )
    }
    
    function user_detail
    {
        // called with user2/user_detail/[user_id]
        // displays one user in a table form by passing user_id to
        // model: model_users "get" function
        // to populate the view: user_detail_form
        // (note: view_user_detail_form will have two submit buttons ("Update" and "Delete")
    }
    
    function delete
    {
        // called with user2/delete/[user_id]
        // asks for confirmation-cancellation before passing user_id to
        // model: model_users "delete" function
        // after deletion, redirect to user2/list_all and add line for to show user_id deleted
    }
    
}

Thanks in advance. I need to get off of these T_OBJECT errors, whatever the heck they are.

#2
[eluser]sophistry[/eluser]
you are missing the dollar sign in front of this. as in $this

#3
[eluser]CheekyGeek[/eluser]
Oh Crikey. THANKS and sorry to bother the forum with such a dumb miss.
:\
You'll be happy know that the following 5 or 6 errors were every bit as dumb (if not more so), but I solved them without troubling the forum!
Smile

#4
[eluser]CheekyGeek[/eluser]
I'm stuck again, this time with another
Code:
Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in /Library/WebServer/Documents/CI/system/application/models/users_model.php on line 9

Here is the model - what in the world is the problem with line 9?

Code:
<?php

class Users_model extends Model
{

    var $user_id     = '';
    var $username     = '';
    var $password    = '';
    var $last_name    = '';
    var $first_name = '';    
    var $phone        = '';    
    var $email        = '';    
    var $org         = '';    
    var $admin        = '';    

    function Users_model() {

        // All models need to call the constructor of the parent Model class
        parent::Model();

    }



    function get() {

        // BEGIN FILTER CRITERIA CHECK
        // If any of the following properties are set before users_model->get() is called from the controller then we will include
        // a where statement for each of the properties that have been set.
        if ($this->user_id) {
            $this->db->where("user_id", $this->user_id);
        }

        if ($this->username) {
            $this->db->where("username", $this->username);
        }

        if ($this->password) {
            $this->db->where("password", $this->password);
        }

        if ($this->last_name) {
            $this->db->where("last_name", $this->last_name);
        }

        if ($this->first_name) {
            $this->db->where("first_name", $this->first_name);
        }

        if ($this->phone) {
            $this->db->where("phone", $this->phone);
        }

        if ($this->email) {
            $this->db->where("email", $this->email);
        }

        if ($this->org) {
            $this->db->where("org", $this->org);
        }

        if ($this->admin) {
            $this->db->where("admin", $this->admin);
        }
        // END FILTER CRITERIA CHECK

        // We will display our results in order by last name and then first name.
        $this->db->orderby("last_name, first_name");

        // This will execute the query and collect the results and other properties of the query into an object.
        $query = $this->db->get("users");

        // If you set users->user_id from your controller, then there will only be one row to return.
        if ($this->user_id) {
            return ($query->row());
        }

        // If mdl_users->users_id was not specified in the controller, then we will return the results as a result set.
        else {
            return ($query->result());
        }

    }

    function save() {

        // When we insert or update a record in CodeIgniter, we pass the results as an array:
        $db_array = array(
        "user_id" => $this->user_id,
        "username" => $this->username,
        "password" => $this->password,
        "last_name" => $this->last_name,
        "first_name" => $this->first_name,
        "phone" => $this->phone,
        "email" => $this->email,
        "org" => $this->org,
        "admin" => $this->admin);

        // If mdl_users->contact_id was set in the controller, then we will update an existing record.
        if ($this->users_id) {
            $this->db->where("users_id", $this->users_id);
            $this->db->update("users", $db_array);
        }

        // If mdl_users->users_id was not set in the controller, then we will insert a new record.
        else {
            $this->db->insert("users", $db_array);
        }

    }

    function delete() {

        // As long as mdl_contacts->contact_id was set in the controller, we will delete the record.
        if ($this->users_id) {
            $this->db->where("users_id", $this->users_id);
            $this->db->delete("users");
        }

    }

}
?>

#5
[eluser]CheekyGeek[/eluser]
Solved it by turning on "invisibles" in BBEdit and saw there was a different character of some kind (not spaces or tabs). Did a BBEdit search and replace to get rid of the weird characters and replace with tabs and now it works. Anybody have any idea what they are or how they got there? I copied and pasted the model code from a tutorial web page. Image of the invisibles here:

http://cgi.unk.edu/tmp/what-the.png

I'm going to paste the characters in code to see if they show up here:
Code:
   

Edit: They don't show up, but if you drag your cursor you can select them.

#6
[eluser]sophistry[/eluser]
that sometimes happens when you copy paste code from a web page.

i use the bbedit function "Tools>Convert to ASCII..." to get rid of them.

cheers.

#7
[eluser]Unknown[/eluser]
[quote author="sophistry" date="1214273496"]you are missing the dollar sign in front of this. as in $this[/quote]
whoa,, i miss the $ too,,
by the way,, thanks.. Big Grin


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.