Yardım gerekli: php Codeigniter profesyonel yapısı

0 Cevap php

Ben önümüzdeki ay mezun duyuyorum. Ben giriş seviyesi php geliştirici iş başvurusu duyuyorum. Birçok şirket, örnek kod göndermek istiyoruz.

Ben örnek kontrolör, görünümü ve model dosyaları ve çıkışların bazı ekran yolluyorum, ama ben üzerinden almıyorum.

Lütfen bana yardımcı olun. Nerede yanlış yapıyorum? Ne ben onları göndermek gerekiyor? Yazma / yapılandırma kodunun herhangi bir profesyonel bir yolu var mı?

Benim örnek kod dosyaları:

Controller

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

?>

View

<?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> 

</div> 

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

Model

<?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 Cevap