熟悉了yii framework之后,今天我的主要任务分别如下:
1:将前后台页面通过yii框架,部署起来,可以通过yii框架进行访问;
2:实现yii的url美化(为了方便以后网站的SEO,提前我把这个考虑进去);
3:实现对数据模型的增删改查。
经过一番努力后,终于完成了工作(界面比较丑陋,是因为还没有开始好好的设计,先实现功能),效果如下:
前台:
访问的URL为:http://localhost/sensi/index/index.php/index/index,这个URL实现了对搜索引擎比较友好的路径方式。
后台:
访问路径:http://localhost/sensi/index/index.php/houtai/manager/login
访问路径为:http://localhost/sensi/index/index.php/houtai/admin/main
实现了界面之后,下面就是对数据模型的增删改查了。由于有Grails的开发经验,这个YII的数据的增删改查,很快也搞定了,下面我贴出增删改查的代码,由于时间关系,后边我会专门抽出时间去细致的讲下这个增删改查的原理,代码如下:
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class NewsController extends Controller {
//Add News
public function actionAdd() {
$news_model = new News();
// $news_model->title = "测试的第6条新闻标题";
// $news_model->pubdate = date("Y-m-d H:i:s", time() + 8 * 3600);
// $news_model->author = "yuanpengfei";
// if ($news_model->save()) {
// echo "success save";
// } else {
// echo "failed save";
// }
if (isset($_POST['News'])) {
foreach ($_POST['News'] as $k => $v) {
$news_model->$k = $v;
}
$news_model->pubdate = date("Y-m-d H:i:s", time() + 8 * 3600);
if ($news_model->save()) {
echo "success save data";
}
}
$this->renderPartial('add', Array('news_model'=>$news_model));
}
//Del News
public function actionDel($id) {
$news_model = News::model();
$news_one = $news_model->findByPk($id);
//echo $news_one;
if ($news_one->delete()) {
echo "success delete data";
//$this->redirect('./show');
}
}
//Update News
public function actionUpdate($id) {
$news_model = News::model();
$news_one = $news_model->findByPk($id);
if (isset($_POST['News'])) {
foreach ($_POST['News'] as $k => $v) {
$news_model->$k = $v;
}
$news_model->updatedate = date("Y-m-d H:i:s", time() + 8 * 3600);
if ($news_model->save()) {
echo "success save data";
}
}
$this->renderPartial('show', array('news_model'=>$news_model));
}
//List News
public function actionList() {
$news_model = News::model();
$news_list = $news_model->findAll();
foreach($news_list as $_v){
echo $_v->title,"----",$_v->pubdate,"<br />";
}
}
}
下面的工作便是将增删改查的逻辑,通过页面来进行操作。
文章的脚注信息由WordPress的wp-posturl插件自动生成
微信扫一扫,打赏作者吧~![[整理][转载]win下网卡抓包发包库Npcap使用](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2023/08/demo_1-1024x711.jpg&w=280&h=210&zc=1)
![[转载]基础数据char,int,double,string是线程安全的吗?](http://www.jyguagua.com/wp-content/themes/begin/img/random/3.jpg)
![[整理]how to run flask with pyqt5](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2021/03/pyqt_flask.png&w=280&h=210&zc=1)
![[已解决]LINK : fatal error LNK1158: cannot run 'rc.exe' 错误的解决办法](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2021/02/Snipaste_2021-02-17_15-18-26-1024x505.png&w=280&h=210&zc=1)