Jump to content

Coding Help


bunoire14

Recommended Posts

Hey Guys,

I'm in the process of creating a "Job Center" module for PHPvms. The idea beign that the admin can insert jobs available within the VA and have people browse  and apply for them right through the website.

Its still early doors and MVC approach to PHPvms is new to me... my experience thus far has been in procedural PHP.

So far what Ive done is referenced both the built in "News"  module and the "Exam Center" module availbe for download here on the forums as examples to follow.

I have created a JobsData.class.php which is handling all my calls to the database to retireve data (and eventually will input/edit and delete).

I have made jobs.php which is inside the module directory and is dealing with calling the functions from the Jobsdata.php ,

and I have two .tpl files.. one designed to just list the currently available jobs and a further one to display the job details as a user clicks on a heading from the Job List.

I think im halfway there to getting this sussed, however im getting this error:

Warning: Invalid argument supplied for foreach() in C:Usersbunoire14DesktopDevVMScorecommonJobsData.class.php on line 19

now heres my script:

public function GetJobs($count='')
{
	$sql='SELECT job_ref, job_title,date_posted, posted_by FROM new_jobs ORDER BY postdate DESC 
			LIMIT '.$count;

	$result =  DB::get_results($sql);
		foreach($result as $row)
		{
		$this->set('jobref', $row->job_ref);
		$this->set('title', $row->job_title);
		$this->set('postedby', $row->posted_by);
		$this->set('postdate', date('d/m/Y', $row->date_posted));
	}
}
}

I have read the API and it says that the DB::get_results() returns an array but it seems im not handling that array correctly, can anyone shed any light on this as I'm lost!

Cheers,

Link to comment
Share on other sites

  • Administrators

Hey,

The data classes should only be to get/retrieve data, no template calls. So, the $this->set and $this->render's won't run in data classes. Check out the other data classes to see how I do it, that will help

Do this:

return DB::get_results($sql);

And process the results in the controller.

You can refer to the Frontmap module too, those are a little easier to see. The invalid argument means the DB didn't return properly, after DB::get_results() do DB::debug() to see the errors.

And you should do:

if($count != '')

{

  $sql. = ' LIMIT '.$count;

}

To only include the LIMIT param is $count ins't blank. That's probably your error there

Link to comment
Share on other sites

  • Administrators

No problem.

The best example I guess would be the Profile module, the view function (it uses a few different data functions, returns the data and sets them to a template), or for processing, the RouteMap module (I think the video tutorial goes over this), or the XML module.

I'm gonna be re-doing a tutorial on this sometime this week to coincide with the release, but definitely, any questions let me know. There's all sorts of info strewn around, so I have to try to get it all together.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...