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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:32:18+00:00 2026-05-23T13:32:18+00:00

CodeIgniter has a method $this->load->vars($array) that is ideally used in the parent Controller to

  • 0

CodeIgniter has a method $this->load->vars($array) that is ideally used in the parent Controller to provide global access to system variables directly in the view. For example:

$this->data['username'] = "john";
$this->load->vars($this->data);

Then in the view, you can easily access john by echoing $username.

My question is, is it possible to use $this->load->vars($array) from within a Model instead of a Controller? This will allow me to abstract away some details from my Controller, making it cleaner. What changes would I have to make to get this working? Would you recommend it; do you think it breaks MVC?

Also, I’m using Datamapper ORM, so my models actually extend the Datamapper object and not the Model object.

Thanks!

  • 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-05-23T13:32:19+00:00Added an answer on May 23, 2026 at 1:32 pm

    Is it possible to use $this->load->vars($array) from within a Model instead of a Controller?

    As mentioned, yes you can do this, you can even load a view from a Model, or even run $this->load->vars() in a view and load yet another view.

    This will allow me to abstract away some details from my Controller, making it cleaner.

    This is like sweeping the dirt under the rug, it didn’t go away – it just went somewhere else where you are bound to deal with it later.

    Would you recommend it; do you think it breaks MVC?

    It’s not going to “break” anything, but it implies that maybe your concept of MVC is somewhat broken. If it has nothing do do with the data layer and everything to do with the view layer, it doesn’t belong in the Model. There’s a good chance there may be some other stuff that doesn’t quite belong there as well…

    I’m using Datamapper ORM, so my models actually extend the Datamapper object and not the Model object.

    You may need to call get_instance() and assign it to a variable or class property for use in DM models, so you can access the Codeigniter object.

    Example: $CI =& get_instance(); $CI->load->vars();

    Suggestion:

    Return the data from the Model in the simplest, most reusable form possible, and then assign it to the view variables in the Controller. If I’m hunting down the source of some variables in a view file, the last place I’d look for them is in the Model. You may end up revisiting this project in the future, so try to be consistent as much as you can, and stick to the suggested, expected practices.

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

Sidebar

Related Questions

CodeIgniter allows access to POSTed data via: $this->input->post('input_name'); where 'input_name' is the name of
This has bothered me for quite a while, but now it is necessity that
I have a CodeIgniter MVC application. I have a model called city that has
I'm creating a form in CodeIgniter that has a paired value- Companies, and CEOs.
I'm using the CodeIgniter PHP framework. I have a simple form that has an
using CodeIgniter normally one has to specify the controllers in the config/routes.php file. This
In Kohana/CodeIgniter, I can have a URL in this form: http://www.name.tld/controller_name/method_name/parameter_1/parameter_2/parameter_3 ... And then
I know that codeIgniter turns off GET parameters by default. But by having everything
I am writing a webapp using CodeIgniter that requires authentication. I created a model
Im building a codeigniter app which uses json_encode to provide ajax data in many

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.