PHP - Codeigniter专业结构

Raj*_*Raj 3 php codeigniter

我将在下个月毕业.我正在申请入门级php开发人员工作.许多公司都要求发送示例代码.

我正在发送样本控制器,视图和模型文件以及输出的一些屏幕截图,但我没有通过.

请帮我.我在哪里做错了?我应该寄给他们什么?有没有专业的编写/构建代码的方法?

我的示例代码文件是:

调节器

<?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. */

?>
Run Code Online (Sandbox Code Playgroud)

视图

<?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');?>
Run Code Online (Sandbox Code Playgroud)

模型

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

}

?>
Run Code Online (Sandbox Code Playgroud)

Wou*_*elo 7

  1. 您可以从Controller类(MVC)中删除HTML标记开始
  2. 创建propper文档(@return,@ param等)
  3. 大多数公司希望在实时服务器上看到代码+该代码的工作版本
  4. 如果它不是CodeIgniter特定的作业,则还显示非CodeIgniter代码
  5. 显示你可以读/写UML图表
  6. 添加一些变体(XML,SOAP,OOP,不同的dbtypes,文件上传,会话,安全性等)
  7. 指出您通过至少测试驱动开发或行为驱动开发来构建代码

祝你好运!祝你好运!