php第五章
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php第五章,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2420字,纯文字阅读大概需要4分钟。
内容图文
![php第五章](/upload/InfoBanner/zyjiaocheng/1254/73569df7fa8d4962833380616f3ca301.jpg)
yii框架
指定控制器
?r=hello/index表示:index.php 跳转到HelloController控制器中actionIndex函数
例子:
http://localhost:63342/htdocs/yii_basic/web/index.php?r=hello/query
HelloController.php
<?php /** * Created by PhpStorm. * User: forr * Date: 15/10/2 * Time: 12:02 */ namespace app\controllers; use yii\web\Controller; use app\models\FirstTest; class HelloController extends Controller { publicfunction actionIndex() { $request = \YII::$app->request; echo$request->get(‘id‘); // echo ‘hello world 23333333‘; //跳转 // $this->redirect(‘https://www.baidu.com/‘); //下载文件 // $response = \YII::$app->response; // $response->sendFile(‘./favicon.ico‘);//路径web/favicon.ico } //查询数据publicfunction actionQuery() { echo ‘my db‘; $sql = ‘select * from first_test where id = :id‘; $list = FirstTest::findBySql($sql,array(‘:id‘=>1))->all(); print_r($list).‘<br/>‘; //批量查询每次查询2条记录$sql = ‘select * from first_test‘; foreach(FirstTest::find()->batch(2) as$test) { echocount($test); } } //删除数据publicfunction actionDelete() { // $sql = ‘select * from first_test where id = :id‘; // $list = FirstTest::findBySql($sql,array(‘:id‘=>4))->all(); // $list[0]->delete(); //或 FirstTest::deleteAll(‘id = :id‘,array(‘:id‘=>3)); } //添加数据publicfunction actionAdd() { $test1 = new FirstTest(); $test1->name = ‘张杰‘; $test1->title = ‘逆战‘; $test1->age = 32; //启动校验规则$test1->validate(); if($test1->hasErrors()) { echo ‘名称过长,不符合规则‘; die; } $test1->save(); } }
FirstTest.php
<?php /** * Created by PhpStorm. * User: forr * Date: 15/10/2 * Time: 16:40 */ namespace app\models; use yii\db\ActiveRecord; class FirstTest extends ActiveRecord{ publicfunction rules() { return [ // 有个有效的名字 [‘name‘, ‘string‘,‘length‘=>[0,10]], ]; } }
Orders.php
<?php /** * Created by PhpStorm. * User: forr * Date: 15/10/2 * Time: 16:40 */ namespace app\models; use yii\db\ActiveRecord; class Orders extends ActiveRecord{ publicfunction getCustomer() { $customer = $this->hasOne(Customer::className(),[‘id‘=>‘customer_id‘])->asArray(); return$customer; } }
Customer.php
<?php /** * Created by PhpStorm. * User: forr * Date: 15/10/2 * Time: 16:40 */ namespace app\models; use yii\db\ActiveRecord; class Customer extends ActiveRecord{ publicfunction getOrders() { $order = $this->hasMany(Orders::className(),[‘customer_id‘=>‘id‘])->asArray(); return$order; } }
原文:http://www.cnblogs.com/huen/p/4852160.html
内容总结
以上是互联网集市为您收集整理的php第五章全部内容,希望文章能够帮你解决php第五章所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】