4,249
社区成员




<?php
require_once __DIR__ .'/../autoload.php';
use Wudimei\DB;
$config = include __DIR__ . "/db_config.php";
DB::addConnection($config);
$select = DB::connection( );
$pg = $select->table("blog")->where('id','>',1)->where('id','<',10)->paginate(2);
echo "<pre>";
print_r( $pg->data );
echo "</pre>";
echo $pg->render("db_paginate.php?page={page}");
<?php
require_once __DIR__ .'/../autoload.php';
use Wudimei\DB;
$config = include __DIR__ . "/db_config.php";
DB::addConnection($config);
$select = DB::connection( );
$data = array(
'title' => 'ha ha 2',
'content' => 'abc2',
'created_at' => date("Y-m-d H:i:s")
);
$intAffectedRows = $select->table("blog")->where('id',1 )->update( $data );
echo $intAffectedRows;
<?php
require_once __DIR__ .'/../autoload.php';
use Wudimei\DB;
$config = include __DIR__ . "/db_config.php";
DB::addConnection($config);
$select = DB::connection( );
$data = array(
'title' => 'ha ha ',
'content' => 'abc',
'created_at' => date("Y-m-d H:i:s")
);
$lastInsertId = $select->table("blog")->insert( $data );
echo $lastInsertId;
<?php
require_once __DIR__ .'/../autoload.php';
use Wudimei\DB;
$config = include __DIR__ . "/db_config.php";
DB::addConnection($config);
$select = DB::connection( );
$intAffectedRows = $select->table("blog")->where('id',12)->orWhere('id',11)->orWhere('id',10)->delete( );
echo $intAffectedRows;
<?php
require_once __DIR__ .'/../autoload.php';
use Wudimei\View;
View::loadConfig( __DIR__ . '/view_config.php' );
$vars = [
'students' => [
['name' => 'jim','age'=>14 ],
['name' => 'lily','age'=>15 ],
['name' => 'lucy','age'=>13 ]
]
];
echo View::make("default.index.foreach",$vars );
<table border="1">
<tr>
<td>name</td>
<td>age</td>
</tr>
@foreach( $students as $stu)
<tr>
<td>{{$stu['name']}}</td>
<td>{{$stu['age']}}</td>
</tr>
@endforeach
</table>
<br /> <br />
@foreach( $students_empty_val as $stu)
{{$stu['name']}} ,
{{$stu['age']}} <br />
@foreachelse
no data
@endforeach
<?php
require_once __DIR__ .'/../autoload.php';
//use Wudimei\View;
use Wudimei\StaticProxies\View;
View::loadConfig( __DIR__ . '/view_config.php' );
View::setForceCompile(true);
View::setSkipCommentTags( true ); // skip <!-- and -->
$vars = [
'success' => true ,
'role' => 'admin' ,
'years' => [2016,2017,2018,2019]
];
echo View::make("default.index.comment_tags",$vars );
comment_tags.view.phtml
<!-- @if( $role == 'admin') -->
hello,{{$role}}
<!-- @else -->
hello,guest
<!-- @endif -->
<!-- @foreach($years as $year) -->
<!-- {{$year}} --><br />
<!-- @foreachelse -->
sorry,years arrary is empty
<!-- @endforeach -->
@if( count( $years) == 4 )
4 years
@else
not 4 years
@endif
<!-- @section('body') -->
this is the body
<!-- @endsection -->