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 8731327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:12:40+00:00 2026-06-13T09:12:40+00:00

I have this code inside my view. $country = array( ‘id’ => ‘country’, ‘name’

  • 0

I have this code inside my view.

$country = array(
    'id' => 'country',
    'name' => 'country',
    'value' => get_user_info('country'),
    'size' => 30
);

<tr>
            <td><?php echo form_label('Country', $country['id']); ?></td>
            <td><?php echo form_input($country); ?></td>
            <td style="color: red;"><?php echo form_error($country['name']); ?><?php echo isset($errors[$country['name']])?$errors[$country['name']]:''; ?></td>
    </tr>

The get_user_info() is a function defined in my form_helper like this:
Form_Helper.php

if(! function_exists('get_user_info')){

        function get_user_info($field)
        {
            $ci = & get_instance();
            $ci->load->model('users');
            return $ci->users->get_user_profile($field);
        }
}

As you can see , inside this function I access the database through the users Model.
User_Model

function get_user_profile($field)
        {
            $user_id = $this->session->userdata('user_id');

            $this->db->select($field);
            $this->db->where('user_id',$user_id);

            $query = $this->db->get($this->profile_table_name);
            if($query->num_rows()==1)return $query->row();

            return NULL;
        }

The idea is to auto fill the Country field of the form while the page loads.
But in the view I am getting this error

A PHP Error was encountered

Severity: Warning

Message: htmlspecialchars() expects parameter 1 to be string, object given

Filename: helpers/form_helper.php

Line Number: 646

What can be the problem ?
Can someone knows what is happening ? Or has someone did a such a thing in the past ?

Is it the right way to access the Model within a helper function ?

Thanks

EDIT
To do better and faster I simply call the model from my controller and then pass the different values to the view.
Controller

$d = $this->users->get_user_profile('country, telephone, city, street, address, town');
        $d2 = Array(
            'telephone' => $d->telephone,
            'country' => $d->country,
            'city' => $d->city,
            'street' => $d->street,
            'address' =>$d->address,
            'town' => $d->town);
        $this->template->write_view('contentw','dashboard/profile', $d2);
        $this->template->render();

So I delete the function I added to my Helper file.

This method is working for me.
Thank you all for your answers

  • 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-13T09:12:41+00:00Added an answer on June 13, 2026 at 9:12 am

    Generally helpers are used as Global functions to do some simple work. Most people would say it is wrong to invoke a Model in the middle of a helper. Helpers should be used like the PHP function explode; it has a single task, receives input, and provides output based on the input very mechanically.

    It might be better instead for the controller to access the model and get that value, then pass it into the view and use it directly

    As for the error:

    You are probably getting that error because you are returning $query->row() instead of an actual value in that field. $query->row() is most likely an object and $query->row()->country is the actual value

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

Sidebar

Related Questions

So I have this code inside my lib/ folder: class GlobalConfig::SetHelper def self.yes_no_input(configuration) value
I have this code which will include template.php file from inside each of these
I have this php code line $data['viewData']['filter'] = isset($parameters['filter']) ? $parameters['filter'] : array('filter1', 'filter2',
I have this code inside my BaseAdapter Adapter: public View getView(final int position, View
I have this code inside a iframe: window.addEventListener('message', function(e){ if(e.data == 'test') console.log(e); },
I have this code inside a header (edited): template <int i> class A {};
I have this code inside thread and when I call terminate it terminates fast
I have this code snippet inside a function that checks if an object exists
I have written this code inside a servlet to delete certain records from three
I have this block of code inside a loop: var points = [new google.maps.LatLng(lat1,

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.