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(){ |
一个控制器就建立好了,控制器也可以设置闭包,也可以设置别名
1 |
Route::get( 'user/profile' , array ( 'as' => 'profile' , function () |
更多路由请看手册: 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)); //删 |
查询生成器
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(); //查询一条数据 |
05 |
$sql = DB::table( 'archives' ) |
06 |
->where( 'typeid' , '=' , 1) |
07 |
->orWhere( function ( $query ) |
09 |
$query ->where( 'id' , '>' , 2) |
10 |
->where( 'title' , '<>' , 'Admin' ); |
12 |
->get(); //sql语句: select * from `la_archives` where `typeid` = 1 or (`id` > 2 and `title` <> 'Admin') |
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' ); //查和 |
20 |
$data = array ( 'title' => '标题八' , 'body' => '内容八' , 'typeid' =>2); |
21 |
$obj = DB::table( 'archives' )->insert( $data ); |
23 |
$data2 = array ( 'title' => '标题九' , 'body' => '内容九' , 'typeid' =>2); |
24 |
$obj = DB::table( 'archives' )->where( 'id' ,2)->update( $data2 ); |
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; //不自动维护更新时间 |
//模型操作和普通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)
2 |
foreach ( $items as $k => $v ){ |
控制器中
1 |
public function test(){ |
2 |
$data = Archives::select( '*' )->get(); |
3 |
return View::make( 'home.test' )->with( 'items' , $data ); |
- 转载ASP.NET MVC 和ASP.NET Web Form简单区别
转载原地址 http://www.cnblogs.com/lei2007/p/3315431.html 概论: Asp.net 微软 提供web开发框架或者技术.分Web Form和ASP.NET ...
- 转载 ASP.NET MVC中使用ASP.NET Identity
转载原地址: http://blog.jobbole.com/90695/ 在之前的文章中,我为大家介绍了OWIN和Katana,有了对它们的基本了解后,才能更好的去学习ASP.NET Identit ...
- 转载ASP.NET MVC中Session的处理机制
本文章转载自 http://www.cnblogs.com/darrenji/p/3951065.html ASP.NET MVC中的Session以及处理方式 最近在ASP.NET MVC项目中 ...
- 【转载】【MVC 学习 Razor语法】
Razor是MVC3中才有的新的视图引擎.我们知道,在ASP.NET中,ASPX的视图引擎依靠<%和%>来调用C#指令.而MVC3以后有了一套新的使用@标记的Razor语法,使用起来更灵活 ...
- [转载] ASP.NET MVC (一)——深入理解ASP.NET MVC
个人认为写得比较透彻得Asp.net mvc 文章,所以转载过来,原文链接在最后: ASP.NET vs MVC vs WebForms 许多ASP.NET开发人员开始接触MVC认为MVC与ASP.N ...
- 转载——Asp.Net MVC+EF+三层架构的完整搭建过程
转载http://www.cnblogs.com/zzqvq/p/5816091.html Asp.Net MVC+EF+三层架构的完整搭建过程 架构图: 使用的数据库: 一张公司的员工信息表,测试数 ...
- 《转载》Spring MVC之@RequestBody, @ResponseBody 详解
引言: 接上一篇文章讲述处理@RequestMapping的方法参数绑定之后,详细介绍下@RequestBody.@ResponseBody的具体用法和使用时机: 简介: @RequestBody 作 ...
- 【转载】Spring MVC 整合 Freemarker
前言 1.为什么要使用Spring MVC呢? 2.为什么要使用Freemarker呢? 3.为什么不使用Struts2呢? 此示例出现的原因就是发现了struts2的性能太差,所以学习Spring ...
- [转载]Spring Web MVC Framework
Required Configuration You need to map requests that you want the DispatcherServlet to handle, by us ...
随机推荐
- C++11 多线程 教学(2)
C++11开始支持多线程编程,之前多线程编程都需要系统的支持,在不同的系统下创建线程需要不同的API如pthread_create(),Createthread(),beginthread()等, ...
- MySql 跟踪命令
SHOW ; SHOW FULL PROCESSLIST; ; USE table1; ; SHOW PROFILES; ; SHOW TABLES; SHOW PROFILES; SHOW PROF ...
- display:inline和display:inline-block的区别
先来一张图: 测试代码: <!DOCTYPE html> <html> <head> <style> #bb { overflow: hidden; b ...
- Android-----------打开手机上的应用
##判断手机上是否存在应用,存在则打开 package com.funs.openApp.utils; import java.util.List; import android.c ...
- arc engine - ILayer.
ILayer ILayer接口是被图层(Layer)对象实现的,图层对象是用来在地图中显示空间信息. 注意,图层不含有空间数据,它只是获取数据的一个引用层而已.图层对象是一个抽象对象,它定 ...
- .NET技术
1.在C#中,string str = null 与 string str = “” 请尽量使用文字或图象说明其中的区别.回答要点:说明详细的空间分配.(10分) 解:string str=null ...
- UI基础视图----UIImageView总结
UIImageView和UILabel一样,也是UIKit框架中非常常用的视图类.继承关系和UILabel完全一致(都是继承于UIView),功能也相似(用户交互都默认为关,主要用于展示),只不过UI ...
- poj 3104 二分
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12568 Accepted: 3243 Descripti ...
- SEO教程:向百度要流量 第一季
首先祝贺你:当你看到这篇文章时,你已经站在一条通往SEO达人捷径的路口. 笔者也是今年年初才成为SEOer的一员,在做SEO的过程中,有不少自己独特的心得体会,所以一直酝酿着写一个SEO系列的文章,将 ...
- FATAL:NO bootable medium found!System halted.
问题描述:致命错误,没有可引导的媒体.系统挂起.以下是在网上查的: 1:检查硬盘的类型,ide或sata接口是否在0,0或是在1,0. 2:光驱是否选择iso文件. 3:iso文件是否损坏4:virt ...