我已经用PHP开发了几年,但我不断质疑的一件事是我是否应该像这样构建我的页面:
if(getValue('action') == "jobsFilter" && getValue('jobType') == "open")
{
$job->FetchJobs($jobStatus = 1);
foreach($job->result AS $pulledJob)
{
?>
<div class = "openJob panelJob col-xs-12">
<h2><?php echo $pulledJob['jobTitle'] ?></h2>
<a href = "?action=viewJob&jobId=<?php echo $pulledJob['Id'] ?>" class = "viewJobBtn ">View Job</a>
</div>
<?php
}
}else if(getValue('action') == "jobsFilter" && getValue('jobType') == "active")
{
$job->fetchAllJobsAppliedToUser($jobStatus = 1);
foreach($job->result AS $pulledJob)
{
?>
<div class = "openJob panelJob col-xs-12">
<h2><?php echo $pulledJob['jobTitle'] ?></h2>
<a href = "?action=viewJob&jobId=<?php echo $pulledJob['Id'] ?>&jobStatus=1" class = "viewJobBtn ">View Details</a>
</div>
<?php
}
}else if(getValue('action') == "viewJob" && isset($_GET['jobId']))
{
$job->FetchJobs($jobStatus = 1, $jobId = $_GET['jobId']);
foreach($job->result AS $pulledJob)
{
?>
<div class = "viewJob panelJob col-xs-12">
<div class = "pulledJobInfo">
<h2><?php echo $pulledJob['jobTitle'] ?></h2>
<p><?php echo $pulledJob['JobDescription'] ?></p>
</div>
<form method = "post" action = "?action=acceptJob">
<input type = "submit" name = "acceptJobSubmitBtn" class = "acceptJobBtn fullWidthButton ctaButton" value = "Let me help" />
<input type = "hidden" name = "jobId" value = "<?php echo $pulledJob['Id'] ?>" />
</form>
</div>
<?php
}
}
或者我是否应该有一个单独的页面,对于打开的作业称为open-jobs.php,对于已关闭的作业称为closed-jobs.php等。
如果有人能够对最佳解决方案有所了解,那就太棒了!
答案 0 :(得分:1)
if(getValue('action') == "jobsFilter" && getValue('jobType') == "open")
{
$job->FetchJobs($jobStatus = 1);
$file="view1"
}else if(getValue('action') == "jobsFilter" && getValue('jobType') == "active")
{
$job->fetchAllJobsAppliedToUser($jobStatus = 1);
$file="view2"
}else if(getValue('action') == "viewJob" && isset($_GET['jobId']))
{
$job->FetchJobs($jobStatus = 1, $jobId = $_GET['jobId']);
$file="view3"
}
if($job != null){
foreach($job->result AS $pulledJob)
{
include($file)
}
}
// Logic what to display
switch(getValue('action')){
case "jobsFilter":
switch (getValue('jobType')){
case "open":
$job->FetchJobs($jobStatus = 1);
$file="view1"
break;
case "active":
$job->fetchAllJobsAppliedToUser($jobStatus = 1);
$file="view2"
break;
}
case "viewJob":
$job->FetchJobs($jobStatus = 1, $jobId = $_GET['jobId']);
$file="view3"
break;
}
// Execute the display
if($job != null){
foreach($job->result AS $pulledJob)
{
include($file)
}
}