0.0.6 • Published 6 years ago
start-yii2 v0.0.6
#Yii2 Build Web Project
###Install Yii2 Project (NewYii2)
cd ~/Documents
composer create-project --prefer-dist yiisoft/yii2-app-basic NewYii2
cd NewYii2
php yii serve
###Edit Code: ./NewYii2/config/web.php
# ...
'components' => [
// ...
//
// Now Active Code
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
//
],
# ...
#Example Conver: http://localhost:8080/index.php?r=name/view
# To : http://localhost:8080/name/view
###Create (Home) Controller: ./NewYii2/controllers/HomeController.php ####( use app\models\ModelsName; ) ####File models ./NewYii2/models/ModelsName.php
<?php
namespace app\controllers;
use yii\web\Controller;
use app\models\ModelsName; #Name models
class HomeController extends Controller
{
//Action
#Render (index)
public function actionIndex()
{
// http://localhost:8080/home/index
#Create in (layouts) folder a (homeLayout) file: ./NewYii2/views/layouts/homeLayout.php
$this->layout='homeLayout';
#Create (home) folder and (index) file: ./NewYii2/views/home/index.php
return $this->render('index');
}
#Models (Name)
public function actionName()
{
// http://localhost:8080/home/name
#Create (Name) file: ./NewYii2/models/ModelsName.php
$model = new ModelsName();
$model->setName('name1','name2','name3');
echo $model->getName();
}
}
###Create (Name) models: ./NewYii2/models/ModelsName.php
<?php
/* @var $this \yii\web\View */
/* @var $content string */
use app\widgets\Alert;
// use yii\helpers\Html;
// use yii\bootstrap\Nav;
// use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
// use app\assets\AppAsset;
// AppAsset::register($this);
?>
<!-- This is header -->
<?php echo 'This is homeLayout'; ?>
<div class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
<!-- This is footer -->
##Push Heroku Master
heroku login
heroku create
Here’s a typical .gitignore file:
add the code:
vendor/
.env
####Create a file: Procfile
web: vendor/bin/heroku-php-apache2 web/
Open composer.json and move yiisoft/yii2-debug, yiisoft/yii2-gii from require-dev to the require
"require": {
"yiisoft/yii2-debug": "~2.0.0",
"yiisoft/yii2-gii": "~2.0.0",
}
"require-dev": {
"yiisoft/yii2-debug": "~2.0.0",
"yiisoft/yii2-gii": "~2.0.0",
}
composer update
git add .
git commit -am "make it better"
git push heroku master
heroku open