Yii ?????? ???? ??? ?? ???
Jun 21, 2023 pm 05:53 PM? ????? PHP ?????? ???? ???? ???? ?? ??? ?? ?? ??????. ?? PHP ????? ??? Yii ?????? ???? ??? ??? ?? ????? ???? ??? ????????.
? ???? Yii ?????? ???? ???? ??? ??? ??????? ??? ??? ???????. ???????? ??? ??, ?? ??, ???? ?? ? ???? ??? ??? ?????. ? ??????? ???? Yii ?????? ??? ?? ?? ???? ??? ? ????.
Yii ????? ??
Yii ?????? ???? ?? ?? ?????? ???? ???. Yii ?????? ??? ?? ??? ????, ?? ????? ???? ??? Composer? ???? ???? ????. ???? ?? Composer? ???? ??? ???? ???.
?? ??? ???? Yii ?????? ??? ? ????.
composer create-project --prefer-dist yiisoft/yii2-app-basic basic
? ??? ?? ??????? ?????. http://localhost/basic? ???? Yii ?????? ????? ?????? ??? ? ????.
??? ??? ??? ? ??? ???
??? ??? ??????? ??? ?? ???? ??? ??? ???? ??? ???? ??? ???. ? ????? MySQL? ??????? ???? ?? ??? ???? ?????.
- ??? ???: ??? ??, ????, ??? ?? ?? ??? ??? ?????.
- ?? ???: ??, ??, ?? ? ?? ??? ?????.
- ?? ???: ??? ID, ?? ID, ?? ?? ? ?? ??? ?????.
- Cart ???: ??? ID, ?? ID, ?? ? ???? ??? ?????.
? ??? ???? ??? ???? ???? ?? ???? ?? ? ????.
? ??? ???? ?? ??? ?? SQL?? ??? ????.
CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(255) NOT NULL, `password` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `product` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `price` float(10,2) NOT NULL, `description` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `order` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `product_id` int(11) NOT NULL, `quantity` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), KEY `product_id` (`product_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `cart` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `product_id` int(11) NOT NULL, `quantity` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `user_id` (`user_id`), KEY `product_id` (`product_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
?? ?????? ???? ?? ???? ??? ???. ??? ???? ?? ??? ??? ???? ???? ?? ???? ?? ??? ?? ???? ?????. ? ???? ??? ? ??? ??? ??? ?? ??? ???? ??? ????.
??? ???? ???
??? ????? ??? ??? ???????. Yii ??????? ????? ?????? ??? ???? ?? ?? ?????. ????? ?? ??? ???? ??? ?? ?? ?? ???? ???? ??? ?????.
?? UserController? ???? ?? ?? ???? ?????. yiiwebController ??? ???? ????? ???????.
Yii??? ????? ???? ??? ?? ?? Controller? ???, ?? ????? ???? ??? ? ? ??? ? ????. ??? UserController ???? ?? ?????.
<?php namespace appcontrollers; use yiiwebController; class UserController extends Controller { public function actionIndex() { return $this->render('index'); } public function actionLogin() { // code for login logic } public function actionRegister() { // code for registration logic } }
? ???? ? ?? ?? ?? ??? ??????. actionIndex() ???? index.php ? ??? ??????. ?? ?? ?? ??? ?????. actionLogin() ? actionRegister() ???? ??? ??? ? ??? ?????.
?? index.php ? ??? ???? ???. ?? ??? ????? ?? ??? ?????. Yii ??????? ???? Yii::$app->view->render() ???? ???? ?? ????????.
views/user ??? index.php ??? ???? ?? ??? ?????.
<?php use yiihelpersHtml; $this->title = 'User'; $this->params['breadcrumbs'][] = $this->title; ?> <h1><?= Html::encode($this->title) ?></h1> <p> Welcome to the user homepage. </p>
? ??? ????? ??? ?? ???? ?????.
Product Controller ? View ??
?? Product Controller ? View ??? ???????. yiidataActiveDataProvider ??? ???? ?? ?? ???? ?????.
ProductController ????? ???? ?? ?? ???? ?????.
<?php namespace appcontrollers; use yiiwebController; use appmodelsProduct; use yiidataActiveDataProvider; class ProductController extends Controller { public function actionIndex() { $dataProvider = new ActiveDataProvider([ 'query' => Product::find(), ]); return $this->render('index', [ 'dataProvider' => $dataProvider, ]); } public function actionAddtocart($id) { // code for add to cart logic } }
??? ??? ?? ?? Product::find()? ???? ?? ??? ?????. ?? ?? ?? ?? ???? ActiveDataProvider? ?? ?? ?? ?????. ?? ?? ????? ??? ???? ?? actionAddtocart() ???? ????.
?? ??? ???? ? ?? ??? index.php ? ??? ???? ???. dataProvider? ??? ???? ???? ?? ??? ????? GridView ??? ?????. ?? ????? ??? ???? ??? ?????.
??? views/product/index.php ??? ?????.
<?php use yiihelpersHtml; use yiigridGridView; $this->title = 'Product'; $this->params['breadcrumbs'][] = $this->title; ?> <h1><?= Html::encode($this->title) ?></h1> <?= GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ 'id', 'name', 'price', 'description', [ 'class' => 'yiigridActionColumn', 'buttons' => [ 'addtocart' => function ($url, $model) { return Html::a('Add to cart', ['product/addtocart', 'id' => $model->id]); } ], 'template' => '{addtocart}', ], ], ]); ?>
?? ?????? http://localhost/basic/product/index? ???? ?? ???? ?????? ??? ? ????.
???? ???? ?? ? ?
??? ????? ?? ??? ???? ???? ???? ????? ?? ?????. ???? ???? ???? ?? ??? ??? ????.
CartController ????? ???? ?? ?? ???? ?????.
<?php namespace appcontrollers; use yiiwebController; use Yii; class CartController extends Controller { public function actionIndex() { $cart = Yii::$app->session->get('cart'); return $this->render('index', [ 'cart' => $cart, ]); } public function actionAdd($id) { // code for add product to cart logic } public function actionRemove($id) { // code for remove product from cart logic } }
? ????? ?? ??? ??? ???? ???? ?????. actionAdd($id) ?????? ??? ID ??? ?? ??? ????? ?????. actionRemove($id) ?????? ?????? ??? ID ??? ?? ??? ?????.
???? ???? ??? ???? ? ?? ??? index.php ? ??? ???? ???. ??? ??? ???? ???? ???? ???? ??? ????? ListView ??? ?????. ?? ????? ?? ?? ?? ???? ???? ?????? ??? ???? ? ?? ??? ??????.
??? views/cart/index.php ??? ?????.
<?php use yiihelpersHtml; use yiiwidgetsListView; $this->title = 'Shopping Cart'; $this->params['breadcrumbs'][] = $this->title; ?> <h1><?= Html::encode($this->title) ?></h1> <?= ListView::widget([ 'dataProvider' => $dataProvider, 'itemView' => '_cart_item', 'emptyText' => 'Your cart is empty.', ]) ?>
在views/cart文件夾下創(chuàng)建_cart_item.php視圖文件,該文件將被用于渲染購物車列表中的每一行。以下是views/cart/_cart_item.php文件的代碼:
<?php use yiihelpersHtml; use yiiwidgetsActiveForm; $form = ActiveForm::begin([ 'id' => 'cart-item-' . $model['id'], ]); ?> <?= Html::a('Remove', ['cart/remove', 'id' => $model['id']]) ?> <?= $model['name'] ?> <?= $form->field($model, 'quantity')->textInput(['value' => $model['quantity']]) ?> <?= Html::submitButton('Update') ?> <?php ActiveForm::end(); ?>
以上代碼將會在瀏覽器中顯示購物車列表,用戶可以在該列表中執(zhí)行增加或減少商品數(shù)量的操作,也可以刪除購物車中已有商品。
完成在線商城應(yīng)用程序
現(xiàn)在,我們已經(jīng)完成了基礎(chǔ)的在線商城應(yīng)用程序,該應(yīng)用程序擁有用戶管理,產(chǎn)品管理和購物車等基礎(chǔ)功能。該應(yīng)用程序可以作為初學(xué)者學(xué)習(xí)和實踐Yii框架的入門實踐。當(dāng)然,在實際應(yīng)用中,我們?nèi)孕枰砑痈喙δ軄頋M足商城的需求。
? ??? Yii ?????? ???? ??? ?? ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

?? ???? Gree+ ??????? ??? ??? ??? ?? ??? ?????. ??? ??? ?? ?? ???? ?? ?? ?????. ?? ????? Gree+ ?????? ?? ??????. ?? ?? ??? ??? ?? ????? ? ???? ?? "?" ??? ???? ?? ?? ???? ?????. 2. ? ???? ??? ? "??" ??? "?? ???" ??? ????. ?? ? ???? ?????. 3. ???? ??? ???? ???? ???? ????? ?? ?? ??? ??? ?? ??? ???? ?? ? ??? ??? "??" ??? ?????. 4. ????? ??? ??? "?? ??" ???? ??? ???? ????? ?????? ?????.

??: Realme Phone ??? ???: Realme Phone?? ??? ??? ??? ?????? ?? ???? ???? ???? ?? ???? ? ? ??? ?????. ?? ???? ???? Realme Phone? ???? ???? ?? ??? ?????? ??? ?? ????. Realme ???? ???? ???? ?? ???? ???? ?? ??? ??????? ???? ?? ??? ??? ? ???, ??? ??? ?? ???? ?????. ? ????? ???? ??? ???? ? ? ??? ? ??? Realme ????? ??? ??? ??? ?????. ???.

Windows?? ?? ?? ??? ?? ??? ???? ? ??? ??? ? ??? ???? ????. GIMP? ?? ?? ??? ?? ??? ???? ???? ???? ???? ?? ?? ? ??? ???? ? ??? ??? ?? ????????. ???? ?? ???? ???? ??? ?? ???, ??? ???? ??? ?? ??? ?? ??? ??? ???? ??? ??? ? ??? ?? ??? ??? ??? ??? ? ????. ???? ?? ??? ??? ?? Windows PC?? ??? ???? ?? ??? ??? ?? ??? ??? ????. ??? ?????? ??? ?? ?? ????? ?????. ? ???? ????. ??? ??? ??? ?????. ?? ??? ?????. ??? ??? ??? ?????. ??

Highcharts? ???? ?? ??? ??? ???? ?? ?? ??? ?????. ??: ?? ??? ???? ?? ?? ? ?? ??? ???? ? ????? ???? ?? ???? ??? ?? ??, ?? ?? ? ?? ??? ????? ??? ? ????. Highcharts? ??? ?? ??? ??? ?? ??? ???? ??? JavaScript ?? ????????. ? ????? Highcharts? ???? Gantt ??? ??? ??? ???? ???? ?? ??? ?????. 1. ????

Django ???? ??? ?????. ????? ???? ? ?? Django ????? ????. Django? Python? ???? ?? ? ?????? ??? ??? ?? ??? ??? ?????. ? ????? ????? ???? ? ?? Django ????? ??? ??? ?????. ???? ?? Python? Django? ???? ??? ?????. 1??: ???? ???? ?? ?? ??? ?? ?? ? ????? ?????.

iOS17?? Apple? ????? ???? ?? ? ??? ?? ??? ??? ??? ??????. ? ??? ?? ???? ? ???? ?? ???? ???? ??? ? ?? ???? ?? ????? ????? ?? ? ????. ??? ???? ???? ?? ???? ? ??? ???? ?? ? ??? ?? ??? ??? ??????. ? ??? ?? ???? ??? ???? ?? ??? ?? ? ???? ?? ???? ??? ??? ? ?? ??? ?????? ?? ??????. iOS17? Apple? iPhone ????? ??? ???? ??? ??? ???? ??? ??? ??? ???? ??????. ??? ??? ??? ???? ?? iPhone ????? ??? ? ???? ???? ???? ??? ? ????. ?

MDF ??? ???? ?????? ?? ???? Microsoft SQL Server ??????? ?? ?? ? ?????. ?????? ?? ????? MDF ??? ???, ???, ?? ???? ?? ???? ??????? ?? ???? ???? ? ?????. MDF ??? ??? ?? ??????? ??? ?? ?? ? ?????. ????? ? ?? ???? ??? ?????. SQLServerManagementStudio(SSMS)SQLServerManag ??

???? ??? ??? ?? ??? ??? ? ??? ?? ? ????. ???? ???? ??? ??? ??? ????. ??? ???? ??? ??? ??? ?? ??? ???????. Scanner King ?? ???? Scanner King ?? ?? ?? ?? 1. ?? Scanner King ?? ?? ?? ??? ??? ??? ?? [? 3?] ??? ?????. 2. ??? ??? ?? ???? ?????. 3. ??? ?? ?? ???? ? ?? ??? ??? ???? [??]? ?????. 4. ????? ??? ??? ? ??? ???? ? ?? ???? ?????. ?? ??? ??? ???
