网站制作学习网PHP→正文:内容管理demo之route controllers-CI(codeigniter)PHP框架
字体:

内容管理demo之route controllers-CI(codeigniter)PHP框架

PHP 2012/6/6 18:40:15  点击:不统计


学习codeigniter几天后,根据前面学习的做了一个简单的demo,内容管理,很简单,顺便把前面的复习一下 ,本文是route路径和controllers 内容
route路径内容
$route['news'] = 'news/index';
$route['news/(:num)'] = 'news/index/$1';
$route['news/(:any)'] = 'news/$1';

controllers 的内容
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class News extends CI_Controller {
    public function __construct(){
      parent::__construct();
      $this->load->model('news_model');
    }
    public function index($pn=1)
    {
    $data['news']=$this->news_model->get_news($pn);
    $data['title'] = '新闻列表';
    $this->load->view('news/index.html', $data);
    }
    public function show($id){       
     
    }
    public function add(){
    $this->load->view('news/add.html');       
    }
    public function addaction(){//这里采用的是 定义的{}模板符
     $this->load->library('parser');    
     if($this->news_model->addaction()){
        $data['message']="添加成功!";
     }else{
        $data['message'] ="添加失败" ;
      }
     $this->parser->parse("message.html",$data);
   
    }
    public function change($id){
       $data = $this->news_model->get_news_id($id);   
       if($data){
        $this->load->view('news/change.html',$data);  
       }else{
        $this->load->view('message.html','没有该新闻或者参数错误!');
       }      
    }
    public function changeaction($id){
        $this->load->library('parser');
        if($this->news_model->changeaction($id)){
         $data['message']    ='修改成功!';
        }else{
         $data['message'] ='修改失败!';
        }
       $this->parser->parse("message.html",$data);
       // redirect('/login/form/', 'refresh');
 
    }
      
}
这里是两个模块内容。


转www.载for网站制作学习asp必.cn究

·上一篇:模型Model-CI(codeigniter)PHP框架 >>    ·下一篇:内容管理demo之View-CI(codeigniter)PHP框架 >>
推荐文章
最新文章