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

  • Home
  • SEARCH
  • 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 8419087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:30:51+00:00 2026-06-10T02:30:51+00:00

Inside my Model i have this code, this is partial code protected function afterFind

  • 0

Inside my Model i have this code, this is partial code

protected function afterFind ()
{
    $car= Car::model()->findAll("car_id = '{$this->model_id}'");
    foreach($car as $cars) {
        $val['car_name'][] = $cars->car_name;
        $val['car_value'][] = $cars->car_value;
    }
    $this->car_arr = $val;

    parent::afterFind();
}

How do i pass array to view? When i do something like this, there was an error output by YII saying
htmlspecialchars() expects parameter 1 to be string, array given

  • 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-10T02:30:52+00:00Added an answer on June 10, 2026 at 2:30 am

    Yii afterfind() method is overrided to Postprocess AR attributes.

    From the docs:

    This method is invoked after each record is instantiated by a find
    method. The default implementation raises the onAfterFind event. You
    may override this method to do postprocessing after each newly found
    record is instantiated. Make sure you call the parent implementation
    so that the event is raised properly.

    So it usually works like:

    protected function afterFind()
    {
    
      $this->attribute_a = customize($this->attribute_a); //return customized attribute_a
      $this->attribute_b = customize($this->attribute_b); //return customized attribute_b
      ....
      parent::afterFind(); //To raise the event
    }
    

    I am not sure what are you trying to do? but may be you want to automate some task (populating some array) after each find !!

    In that case you can define a public array in your model:

    $public car_arr = array();

    Then populate it in your afterFind() and it will be accessible in the View.

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

Sidebar

Related Questions

Inside my Model I have this code: [Required(ErrorMessage = News content is required.)] [DisplayName(News
i have this code <tr> <td width=300> <label for=tag>Model</label> </td> <td> <td width=10>:</td> </td>
I have this piece of code in a model that sets a start date
I have installed rapache and I am trying to fit a linear model inside
I have a problem with calling a property() inside a dynamic model in Django.
I've been trying to use a List<> of a Model.Person that I have inside
I am looking inside the code of an air quality model written in fortran,
I have a partial view that loops through its Model (a list of things)
I have a partial view for displaying a list of items, I use this
I have a HTML table with a column per row with this html code

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.