1

I got this error:

A PHP Error was encountered Severity: Notice Message: Undefined property: stdClass::$positionsNum

when i run.

My model:

public function load_job($id){        
    $Where = array('jobs.id' => $id);
    $this->db->select('jobs.id, positionsNum, companyName, contract_type.titleEN as contractType');
    $this->db->from('jobs');
    $this->db->join('contract_type', 'jobs.contractTypeId = contract_type.id', 'left');
    $this->db->where($Where);
    $Result = $this->db->get(); 
    return $Result->first_row() ; 
} 

my view:

   <?php if(isset($job) && count($job) > 0){   ?>
   <div class="row job-detail-row">
      <div class="col-lg-6 job-detail-label"><?php echo lang('contractType'); ?></div>
       <div class="col-lg-6"><a href=""><?php  if(isset($job->contractType)) echo $job->contractType; ?></a></div>
      </div>

      <div class="row job-detail-row">
        <div class="col-lg-6 job-detail-label"><?php echo lang('num_vacancies'); ?>    </div>
        <div class="col-lg-6"><?php  echo $job->positionsNum; ?></div>
      </div>
      <?php } ?>

my Controller's function:

public function job() {

    $job_id = $this->uri->segment(3);

    if(isset($job_id) && !empty($job_id))
    {
        //one job
        $job = $this->job_model->load_job($this->GetLang, $job_id);
        $data['job'] = $job;
        $this->load->view( 'front/singleJob', $data);
    }
}

Also, i printed the returned object and it returns this:

stdClass Object(
   [id] => 9
   [positionsNum] => 2
   [companyName] => 
   [contractType] => type1
  )

But, contractType won't be printed in page even if it is already has a value. I can't figure out the problem. Any help?

2
  • Please write code of your controller. Are you properly passing values from model to view? Commented Apr 29, 2014 at 7:24
  • OK, i added the controller's function. Commented Apr 29, 2014 at 7:28

3 Answers 3

0

The problem is here. you have a function with one parameter.

public function load_job($id);

but in controller you are passing two values. Try to pass correct values.

$job = $this->job_model->load_job($this->GetLang, $job_id);

it should be like this.

$job = $this->job_model->load_job( $job_id);
Sign up to request clarification or add additional context in comments.

Comments

0

try like this

public function job() {

    $job_id = $this->uri->segment(3);

    if(isset($job_id) && !empty($job_id))
    {
        //one job
        $data['job'] = $this->job_model->load_job($this->GetLang, $job_id);
        $this->load->view( 'front/singleJob', $data);
    }
}

Comments

0

So, it is solved now :) This problem happened twice in two files: First is which stated in my question, and I had an error in another query at the same page. Second problem was in the HTML file. My complete view was like this:

<?php if(isset($service) && count($service) > 0){   ?>
  <div class="row job-detail-row">
  <div class="col-lg-6 job-detail-label"><?php echo lang('contractType'); ?></div>
   <div class="col-lg-6"><a href=""><?php  if(isset($service->contractType)) echo $service->contractType; ?></a></div>
  </div>
  <?php } ?>

  <ul>
  <?php  foreach ($similarServices as $service) { ?> <<========= NOTICE: $service here is the same as the above condition
   <li>           
       <div class="title"><a href="<?php echo site_url('services/service/'.$service->id) ?>"><?php echo $service->title; ?></a>                                        
        </div>
   </li>
  <?php }//end foreach similarServices ?>  
  </ul>

It appeared because i used the same variable name $service, so i changed it and it works now. Hope this helps you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.