学习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');
}
}
这里是两个模块内容。
更多信息请查看IT技术专栏