在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
SlimoreThe fully (H)MVC framework based on the Slim PHP Framwork v2.6.x . Install
composer.json : { "require" : { "slimore/slimore" : "*" }} Install : $ composer install Directory structureSingle module : / app/ controllers/ models/ views/ configs/ routes.php settigns.php public/ .htaccess index.php vendor/ ... composer.json Multi modules : / app/ frontend/ controllers/ models/ views/ backend/ controllers/ models/ views/ api/ controllers/ models/ views/ ... configs/ routes.php settings.php public/ .htaccess index.php vendor/ ... composer.json Usige.htaccess : RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^ index.php [QSA,L] index.php : <?phpdefine('APP_PATH', realpath(__DIR__ . '/../app') . DIRECTORY_SEPARATOR);define('BASE_URL', str_replace('index.php', '', $_SERVER['PHP_SELF']));require __DIR__ . '/../vendor/autoload.php';$app = new \Slimore\Mvc\Application([ 'debug' => true, 'path' => APP_PATH, 'baseURL' => BASE_URL, //'modules' => ['home', 'admin', 'api'], // Multi-Modules //'defaultModule' => 'home', 'autoloads' => [ APP_PATH . 'path/xx/xx' ]]);//$app->dbConnection(); // if using database$app->get("/", function() { echo "Hello world!";});// Routes//$app->get('/news', 'NewsController:read');// or $app->get('/news', controller('index', 'read'));//$app->get('/news', 'Home\Controllers\NewsController:read');// or $app->get('/news', controller('news', 'read', 'Home\Controllers\\'));//$app->post('/news', 'Home\Controllers\NewsController:create');//$app->put('/news/:id', 'Home\Controllers\NewsController:update');//$app->delete('/news/:id', 'Home\Controllers\NewsController:delete');// or/*$app->moduleNamespace('Home\Controllers\\', function($namespace, $app) { //echo $namespace; $ctl = 'IndexController'; //$app->get('/', $namespace . $ctl . ':index'); //$app->get('/news/:id', $namespace . $ctl . ':index'); $app->controller('index', function($controller, $app, $namespace) { //echo $controller . ', ' . $namespace; //$app->get('/news/:id', $namespace . $controller . ':index'); }, $namespace);});*/// Auto routes => /:action, /:controller/:action, /:module/:controller/:action$app->autoRoute();$app->run(); Model : <?phpclass Article extends \Slimore\Mvc\Model{ //protected $table = 'you_table_name'; //protected $primaryKey = 'your_id';}
View : <?php// using php statement?><title><?=$title?></title><?=$var?><?php if ($exp) : ?><?php else : ?><?php endif; ?> Controller : <?php// Multi-module//namesapce Frontend\Controllers;use \Slimore\Database\Manager as DB;class IndexController extends \Slimore\Mvc\Controller{ public function index() { // Using model, same Laravel $article = Article::find(1); // query builder $news = $this->db->table('news') ->select(['nid', 'cid', 'title', 'content', 'add_time']) ->where(['cid' => 0]) ->orderBy('nid', 'DESC') ->get(); //print_r($news); // Basic database usage, same Laravel $results = DB::select('select * from users where id = ?', [1]); // Slim application methods // request $get = $this->request->get(); // response //$this->response->headers->set('Content-Type', 'application/json'); // view $this->view->setData(array( 'color' => 'red', 'size' => 'medium' )); // render views/index.php $this->render('index', [ 'title' => 'Hello world!' . $article->title, 'article' => $article ]); // output json /*$this->json([ 'status' => 200, 'message' => 'xxxxxx', 'data' => $article ]);*/ }}
DependentsComponents
ChangesLicenseThe MIT License. Copyright (c) 2015 Pandao |
请发表评论