#YII Framwwork
-
Intro & install
-
directory
-
controller FirstCOntroller.php url index.php?r=first/index first controller name index function name
-
route
-
model
-
view -- conreoller code public function actionIndex(){ // $this->layout = false; $token = bin2hex(random_bytes(16)); $response = []; $response['name']="Code With Idris"; $response['list']=["Test","Demo","CRUD"];
return $this->renderPartial('index',$response); // with layout // return $this->render('index'); // without layout }
-- view code passing
use yii\helpers\VarDumper;
VarDumper::dump($list);
?>
- open web.php
- set the layout path and layout file
'layoutPath'=>'@app/views/layouts2',
'layout'=>'main2',AppAsset.php clone name is MainAsset.php then open MainAssets.php
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
namespace app\assets;
use yii\web\AssetBundle;
/**
* Main application asset bundle.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class MainAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'https://cdn.jsdelivr.net/npm/tailwindcss@3.3.3/dist/tailwind.min.css',
'css/app.css'
];
public $js = [
'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js',
'https://cdn.jsdelivr.net/npm/alpinejs@3.12.0/dist/cdn.min.js',
'https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4',
'js/app.js'
];
// Add CDN links instead of local files
public $cssOptions = ['position' => \yii\web\View::POS_HEAD];
public $jsOptions = ['position' => \yii\web\View::POS_END];
}- view layour file or others files layout set
<li><a href="<?= Url::home() ?>" class="nav-link px-2 link-secondary">Home</a></li>
<li><a href="<?= Url::to(['site/index']) ?>" class="nav-link px-2 link-secondary">Overview</a></li>
<li><a href="<?= Url::to(['site/inventory']) ?>" class="nav-link px-2 link-secondary">Inventory</a></li>
<li><a href="<?= Url::to(['site/customers']) ?>" class="nav-link px-2 link-secondary">Customers</a></li>
<li><a href="<?= Url::to(['site/products']) ?>" class="nav-link px-2 link-secondary">Products</a></li>
<li><?php echo Html::a('About', ['site/about'], ['class' => 'nav-link px-2 link-body-emphasis']);?></li>- open
web.php
'rules' => [
// Define your routes explicitly
'' => 'site/index',
'first/index' => 'first/index',
// Add more explicit routes here
'say/<message>' => 'site/say',
'mytest'=>'first/test',
[
'pattern' => 'firsts/<other>',
'route' => 'first/info',
'defaults' => ['other' => 'default','key'=>'123456'], // optional
],
'mytest2'=>'first/test2'
],
- open controller `FirstController.php`
```php
public function actionInfo(){
$data = Yii::$app->request->get();
var_dump($data);
return "Inforamtion";
}$data = Yii::$app->db->createCommand('select * from users')->queryAll();
var_dump($data);- clone the file
db.phptodb2.php - and open
web.phpfind the db key and variable for duplicate like below
$db= require __DIR__ . '/db.php';
$db2 = require __DIR__ . '/db2.php';
'db' => $db,
'db2' => $db2,-
query builder query builder open first disable the pretty url and type url like
localhost:8080/index.php?r=gii -
gii
-
advanced
-
advanced directory
-
load css / js separate page like register
-
session
-
component
-
widget
-
pagination