http://my.oschina.net/tongjh/blog/194231

http://baike.baidu.com/view/1020297.htm

一、laravel路由(应用中的大多数路由都会定义在 app/routes.php 文件中)

routes.php

1 Route::get('/test','TestController@index');

一个路由就定义好了,当访问 http://xxx.com/public/index.php/test 时就会去找 app/controllers/TestController.php的index方法 
TestController.php

1 class TestController extends Controller{   
2     public function index(){       
3         echo "hello world";
4     }
5 }

一个控制器就建立好了,控制器也可以设置闭包,也可以设置别名

1 Route::get('user/profile'array('as' => 'profile'function()
2 {
3     echo "hello world";
4 }));

更多路由请看手册: http://www.golaravel.com/docs/4.1/routing/

二、模型 
普通数据库操作

1 $results = DB::select('select * from users where id = ?'array(1));//查
2 $results = DB::insert('insert into users (id, name) values (?, ?)'array(1, 'Dayle'));//增
3 $results = DB::update('update users set votes = 100 where name = ?'array('John'));//更新
4 $results = DB::delete('delete from users where id = ?',array(1));//删

查询生成器

01 //查
02 $obj = DB::table('archives')->select('archives.*','arctype.typename')->where('archives.id','>',2)->join('arctype','arctype.id','=','archives.typeid','left')->orderBy('archives.id','desc')->skip(10)->take(5)->get();//查多条数据
03 $obj = DB::table('archives')->where('typeid','=','1')->orderBy('id','desc')->first();//查询一条数据
04 //where条件分组
05 $sql = DB::table('archives')
06     ->where('typeid''=', 1)
07     ->orWhere(function($query)
08     {
09         $query->where('id''>', 2)
10                 ->where('title''<>''Admin');
11     })
12     ->get();//sql语句: select * from `la_archives` where `typeid` = 1 or (`id` > 2 and `title` <> 'Admin')
13 //聚合查询
14 $users = DB::table('archives')->count();//查总数
15 $price = DB::table('archives')->max('id');//查最大值
16 $price = DB::table('archives')->min('id');//查最小值
17 $price = DB::table('archives')->avg('id');//查平均值
18 $total = DB::table('archives')->sum('id');//查和
19 //增
20 $data array('title'=>'标题八','body'=>'内容八','typeid'=>2);
21 $obj = DB::table('archives')->insert($data);
22 //改
23 $data2 array('title'=>'标题九','body'=>'内容九','typeid'=>2);
24 $obj = DB::table('archives')->where('id',2)->update($data2);
25 //删
26 $obj = DB::table('archives')->where('id','>','100')->delete();

//模型(app/models/Archives.php)

1 class Archives extends Eloquent{   
2     protected $table 'archives';//表名
3     public $timestamps  = false;//不自动维护更新时间
4 }

//模型操作和普通SQL查询一样

1 $arr = Archives::select('archives.*','arctype.typename')->where('archives.id','>',2)->join('arctype','arctype.id','=','archives.typeid','left')->orderBy('archives.id','desc')->skip(0)->take(10)->get();
2 $data array('title'=>'新标题','body'=>'新内容');
3 $arr = Archives::where('id','=',2)->update($data);

三、视图(app/views/home/test.blade.php)

1 <?php
2     foreach($items as $k=>$v){
3         echo $v->title.'<br>';
4     }
5 ?>

控制器中

1 public function test(){
2    $data = Archives::select('*')->get();
3    return View::make('home.test')->with('items',$data);
4 }

【转载】laravel的MVC的更多相关文章

  1. 转载ASP.NET MVC 和ASP.NET Web Form简单区别

    转载原地址 http://www.cnblogs.com/lei2007/p/3315431.html 概论: Asp.net  微软 提供web开发框架或者技术.分Web Form和ASP.NET  ...

  2. 转载 ASP.NET MVC中使用ASP.NET Identity

    转载原地址: http://blog.jobbole.com/90695/ 在之前的文章中,我为大家介绍了OWIN和Katana,有了对它们的基本了解后,才能更好的去学习ASP.NET Identit ...

  3. 转载ASP.NET MVC中Session的处理机制

    本文章转载自 http://www.cnblogs.com/darrenji/p/3951065.html ASP.NET MVC中的Session以及处理方式   最近在ASP.NET MVC项目中 ...

  4. 【转载】【MVC 学习 Razor语法】

    Razor是MVC3中才有的新的视图引擎.我们知道,在ASP.NET中,ASPX的视图引擎依靠<%和%>来调用C#指令.而MVC3以后有了一套新的使用@标记的Razor语法,使用起来更灵活 ...

  5. [转载] ASP.NET MVC (一)——深入理解ASP.NET MVC

    个人认为写得比较透彻得Asp.net mvc 文章,所以转载过来,原文链接在最后: ASP.NET vs MVC vs WebForms 许多ASP.NET开发人员开始接触MVC认为MVC与ASP.N ...

  6. 转载——Asp.Net MVC+EF+三层架构的完整搭建过程

    转载http://www.cnblogs.com/zzqvq/p/5816091.html Asp.Net MVC+EF+三层架构的完整搭建过程 架构图: 使用的数据库: 一张公司的员工信息表,测试数 ...

  7. 《转载》Spring MVC之@RequestBody, @ResponseBody 详解

    引言: 接上一篇文章讲述处理@RequestMapping的方法参数绑定之后,详细介绍下@RequestBody.@ResponseBody的具体用法和使用时机: 简介: @RequestBody 作 ...

  8. 【转载】Spring MVC 整合 Freemarker

    前言 1.为什么要使用Spring MVC呢? 2.为什么要使用Freemarker呢? 3.为什么不使用Struts2呢? 此示例出现的原因就是发现了struts2的性能太差,所以学习Spring ...

  9. [转载]Spring Web MVC Framework

    Required Configuration You need to map requests that you want the DispatcherServlet to handle, by us ...

随机推荐

  1. SWTBOK測试实践系列(4) -- 软件測试技术的黑白之道

    白盒測试和黑盒測试往往是项目中最受争议的两种測试类型,每一个人偏爱各不同.现实生活中行业人员大多喜欢白盒測试而忽视黑盒測试,那么项目中又应该怎样平衡这两类測试呢?我们先来看两个案例. 案例一: 某移动 ...

  2. python查看删除你微信的账号

    #应用环境:python2.7 #!/usr/bin/env python # coding=utf-8 from __future__ import print_function import os ...

  3. 将宿主机东西拷贝到dokcer容器中去

    1,获取容器名称或者id : docker ps 2,获取整个容器的id,其实键盘tag就可以补全的. docker inspect -f  '{{.Id}}'  步骤A获取的名称或者id 3,在主机 ...

  4. .NET基础拾遗(6)特性

    1 神马是特性?如何自定义一个特性? (1)特性是什么     特性是一个对象,可以加载到程序集及程序集的对象中,这些对象包括 程序集本身.模块.类.接口.结构.构造函数.方法.方法参数等,加载了特性 ...

  5. 可用与禁用 E:enabled { sRules }

    <!DOCTYPE html><html lang="zh-cmn-Hans"><head><meta charset="utf ...

  6. C#语法糖: 扩展方法(常用)

    今天继续分享C#4.0语法糖的扩展方法,这个方法也是我本人比较喜欢的方法.大家先想想比如我们以前写的原始类型不能满足现在的需求,而需要在该类型中添加新的方法来实现时大家会怎么做.我先说一下我没有学习到 ...

  7. silverlight visifire控件图表制作——silverlight 静态页面xaml

    一.silverlight 静态页面 1. 时间控件:DatePicker ,添加引用: xmlns:sdk="clr-namespace:System.Windows.Controls;a ...

  8. 实现VS2010整合NUnit进行单元测试

    1.下载安装NUnit(最新win版本为NUnit.3.2.1.msi) http://www.nunit.org/index.php?p=download 2.下载并安装VS的Visual Nuni ...

  9. DTO学习系列之AutoMapper(三)

    本篇目录: Custom Type Converters-自定义类型转换器 Custom Value Resolvers-自定义值解析器 Null Substitution-空值替换 Containe ...

  10. Maybe I go too extreme

    昨天拖着一个没睡好的身体去面试了2家公司 被问到Collection的子集的时候顿时傻了一会,明明很简单的问题一时就想不起来了,哈哈.果然做it的人身体要顾好,状态太差了. 发现了一个问题,其实也是早 ...