2010-11-16 65 views
3

我將在下個月畢業。我正在申請入門級PHP開發人員職位。許多公司都在要求發送示例代碼。PHP - Codeigniter專業結構

我發送示例控制器,查看和模型文件和一些輸出的截圖,但我沒有通過。

請幫幫我。我在哪裏做錯了?我應該送什麼?是否有任何專業的寫作/結構化代碼?

我的示例代碼的文件有:

控制器

<?php 

class NewsRelease extends Controller 
{ 
    function NewsRelease() 
    { 
     parent::Controller(); 
     $this->load->helper('url'); 
     // $this->load->helper('form'); 
     $this->load->model('news_model'); 
     $this->load->library('session'); 
    } 

    /* 
    This is loads the home page called 'home_view'. Before loading this, 
    It checks wheter the admin is logged in or not and clears the admin 
    session. Because, When admin logged out, he will be shown this page. 
    */ 

    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'); 
    } 

    /* 
    On loading the home page, to display all the feature news, the following 
    function is needed. 
    */ 

    function datanews() 
    { 
     //$data['hi']="Hello World"; 
     $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>"; 
     }  
    } 

    /* 
    All the archive news can be shown by this function. 
    */ 

    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>"; 
     } 
    } 

    /* 
    On clicking the Admin link on the home page, he will be navigated 
    to the admin login page. 
    */ 

    function adminlogin() 
    { 
     $this->load->view('adminlogin_view'); 
    } 

    /* 
    The admin login authentication can be handled by thie function. 
    And the session stores his ID and Password. 
    */ 

    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"; 
    } 

    /* 
    After successful authentication, Admin will be shown his home page 
    where he can add, modify and delete the news. 
    */ 

    function adminhome() 
    { 
     if($this->session->userdata('name') && $this->session->userdata('password')) 
      $this->load->view('adminhome_view'); 
    } 

    /* and some more functions go here. */ 

?> 

查看

<?php $this->load->view('header'); ?> 
<!-- scripthome.js has all the javascript and jquery code related to the functions which do the above mentioned process--> 

<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"> 
     <!-- FEATURE NEWS DETAILS--> 
    </div> 
    <!-- 
    The archive page should display a list of all active news items in descending order (newest to oldest 
    based on release date). Similar to the home page, archived news item features a title, a portion of 
    the story and allow the users the ability to either click a title or a "read more" link to view the entire 
    story 
    --> 

    <div id="newsarchivedetails"> 
     <!-- ARCHIVE NEWS--> 
    </div> 

    <div id="newsarchive"> 
     <!-- ARCHIVE NEWS--> 
    </div> 
    <div id="newshome"> 
     <!-- FEATURE NEWS--> 

    </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> 
    <!-- CONTENT CLOSE --> 

</div> 

<!-- WRAPPER CLOSE --> 
<?php $this->load->view('footer');?> 

型號

<?php 

class News_model extends Model 
{ 
    function News_model() 
    { 
     parent::Model();  
    } 

    /* 
    It gets all the featured news from the table News. 
    */ 

    function getactivenews() 
    { 
     $this->db->where('Status','1'); 
     $this->db->where('Type','1'); 
     $this->db->order_by('ID','desc'); 
     return $this->db->get('News'); 
    } 

    /* 
    It gets all the news whose type is '0'(archived) 
    */ 

    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'); 
    } 

} 

?> 
+0

你也許還會看看:http://stackoverflow.com/questions/2048014/structure-codeigniter-application – 2010-11-16 13:44:52

回答

7
  1. 你可以從你的控制器類刪除HTML標籤(MVC)開始
  2. 創建propper文檔(@return,@param等)
  3. 大多數公司希望看到代碼+的工作版本現場服務器上的代碼
  4. 如果它不是一個笨的具體工作,展會還無笨代碼
  5. 顯示他們你可以讀/寫的UML圖
  6. 添加一些品種(XML,SOAP,OOP,不同dbtypes ,文件上傳,會話,安全性, TC)
  7. 點出你的ATLEAST測試驅動開發和行爲驅動開發

而且OFC ..好運建立你的代碼!

+1

顯示你可以在沒有框架的情況下開發應用程序是必不可少的。他們讓事情變得更容易,但是你的未來僱主需要看到你沒有使用CodeIgniter作爲柺杖。 – derekerdmann 2010-11-16 06:40:50

+1

我同意,再加上這會讓我動起來:datanews和archiveNews。爲什麼這麼不一致?我個人認爲這是一個壞習慣,雖然這很小,但這可能是殺手鐗......當然,祝你好運! – JDM 2010-11-16 07:57:10

+1

不只是這樣。代碼的某些部分沒有任何意義。例如。在驗證函數中a)用戶名和密碼是硬編碼的b)不管用戶名/密碼是否正確,會話都被設置c)0或1被回顯,但是這沒有任何作用。我不知道這段代碼是否可行......你最好請一位有經驗的程序員(也許是一位老師)與你一起閱讀你的代碼,讓他/她解釋你所犯的錯誤。 – Mischa 2010-11-16 08:16:06

1

嗯,我想你應該寫自己的結構。發送一些預先構建的代碼是相當容易的,我敢肯定,如果潛在的僱主看到一些獨特的東西,他會更加高興。 當然,如果你正在申請CI的職位,你必須發送一些與CI建立的東西。