學習codeigniter幾天后,根據(jù)前面學習的做了一個簡單的demo,內(nèi)容管理,很簡單,順便把前面的復習一下 ,本文是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','沒有該新聞或者參數(shù)錯誤!');
}
}
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');
}
}
這里是兩個模塊內(nèi)容。
更多信息請查看IT技術專欄
2025國考·省考課程試聽報名