Next month I am finishing my studies. I am applying for entry-level php developers. Many companies ask for a sample code.
I send controller samples, view and model files and some screenshots of the outputs, but I do not receive.
Please help me. Where am I doing wrong? What should I send them? Is there any professional way to write / structure code?
My examples of code files:
controller
<?php
class NewsRelease extends Controller
{
function NewsRelease()
{
parent::Controller();
$this->load->helper('url');
$this->load->model('news_model');
$this->load->library('session');
}
function index()
{
$checksession=$this->session->userdata('name');
if(isset($checksession))
{
$this->session->unset_userdata('name');
$this->session->unset_userdata('password');
}
$this->load->view('home_view');
}
function datanews()
{
$query=$this->news_model->getactivenews();
foreach($query->result_array() as $row1)
{
echo"<p><h4><b><a href='#' id='".$row1['ID']."'>".$row1['Title']."</a>
</h4></b>".substr($row1['Body'],0,100)."<b>...<a href='#'
id='".$row1['ID']."'> read more></b></a></p></br>";
}
}
function archiveNews()
{
$year=trim($this->input->post('year'));
$query=$this->news_model->getArchiveNews($year);
foreach($query->result_array() as $row1)
{
echo"<p><h4><b><a href='#' id='".$row1['ID']."'>".$row1['Title']."</a></h4>
</b>".substr($row1['Body'],0,100)."<b>...<a href='#' id='".$row1['ID']."'>
read more></b></a></p></br>";
}
}
function adminlogin()
{
$this->load->view('adminlogin_view');
}
function validate()
{
$name=trim($this->input->post('name'));
$password=trim($this->input->post('pwd'));
$sess_data=array("name" => $name,
"password" => $password);
$this->session->set_userdata($sess_data);
if($name=="raj"&&$password=="raj")
{
echo "1";
}
else
echo "0";
}
function adminhome()
{
if($this->session->userdata('name') && $this->session->userdata('password'))
$this->load->view('adminhome_view');
}
?>
View
<?php $this->load->view('header'); ?>
<script type="text/javascript" src="<?php echo base_url();?>js/scripthome.js"></script>
<div id="content">
<h3 class="FeatureNews"><a href="#" id="feature"> Feature News </a></h3><h3 class="admin"><?php echo anchor('newsrelease/adminlogin','Admin')?></h3>
<div id="newsdetails">
</div>
<div id="newsarchivedetails">
</div>
<div id="newsarchive">
</div>
<div id="newshome">
</div>
<div id="archivediv">
<h3 class="archive">News Archive by</h3><h3><a href="#" id="2010"> 2010 </a> | <a href="#" id="2009"> 2009 </a> | <a href="#" id="2008"> 2008 </a></h3> <a href="#" id="2007">2007</a>
</div>
</div>
<?php $this->load->view('footer');?>
Model
<?php
class News_model extends Model
{
function News_model()
{
parent::Model();
}
function getactivenews()
{
$this->db->where('Status','1');
$this->db->where('Type','1');
$this->db->order_by('ID','desc');
return $this->db->get('News');
}
function getArchiveNews($year)
{
$this->db->where('year(Date)',$year);
$this->db->where('Status','1');
$this->db->where('Type','0');
$this->db->order_by('ID','desc');
return $this->db->get('News');
}
}
?>
source
share