內(nèi)容管理demo之route controllers-CI(codeigniter)PHP框架

字號(hào):


    學(xué)習(xí)codeigniter幾天后,根據(jù)前面學(xué)習(xí)的做了一個(gè)簡(jiǎn)單的demo,內(nèi)容管理,很簡(jiǎn)單,順便把前面的復(fù)習(xí)一下 ,本文是route路徑和controllers 內(nèi)容
    route路徑內(nèi)容
    $route['news'] = 'news/index';
    $route['news/(:num)'] = 'news/index/$1';
    $route['news/(:any)'] = 'news/$1';
    controllers 的內(nèi)容
    <?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','沒(méi)有該新聞或者參數(shù)錯(cuò)誤!');
    }
    }
    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');
    }
    }
    這里是兩個(gè)模塊內(nèi)容。