您好,我有一段代码:
if($request['txt_!'] != "") {
$randl1_1 = mt_rand(100000, 999999);
} else {
$randl1_1 = '';
}
Run Code Online (Sandbox Code Playgroud)
当我将其转换为三元运算符时:
$randl1_1 = ($request['txt_1'] != "") ? mt_rand(100000, 999999) : '';
Run Code Online (Sandbox Code Playgroud)
如果我在if中添加一些内容怎么办?喜欢,
if($request['txt_!'] != "") {
$randl1_1 = mt_rand(100000, 999999);
someFunction();
} else {
$randl1_1 = '';
}
Run Code Online (Sandbox Code Playgroud)
是否有可能在三元运算符中?
我有这段代码,提交后,它会从数组中生成随机数。
<?php
if(isset($_POST['roll'])) {
$randarray = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
$randselect = array_rand($randarray);
$nr = $randarray[$randselect];
echo '<p class="btn btn-info"> Branch: '. $nr. '</p>';
}
?>
<form action="#" method="post">
<button type="submit" class="btn btn-default" name="roll">Roll Branch </button>
</form>
Run Code Online (Sandbox Code Playgroud)
我想做的是提交表单后,该按钮将被禁用。有什么想法吗?
Hello so I am using slim framework together with PDO connection and is having a big(for me) problem. I wanted to switch with eloquent orm instead of normal try and catching PDO but 45% is already done in my project. So this is my sample code so far
$app->get('/data', function () use ($app) {
try {
$data = $stmt->query("SELECT * FROM tableName");
} catch(PDOException $e) {
die('Error.');
}
$app->render('data.html', array(
'data' => $data
));
});
Run Code Online (Sandbox Code Playgroud)
如何使用纤薄的框架进行分页?这个问题有方法解决吗?谢谢!
我有一个使用相同auth中间件的 API 。因此,当我成功登录时,我被重定向到一个页面,该页面从同一应用程序的 API 中获取数据。在我的app.blade.php我只添加了 axios 和一个简单的 html 并注意,除了在我的表单中的登录页面之外csrf-token,我的标题中甚至没有元数据。@csrf
这是我的app.blade.php布局
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
@yield('content')
<script src="{{ asset('js/axios.min.js') }}"></script>
<script>
const http = axios.create({
baseURL: '/api'
});
http.interceptors.request.use((request) => {
console.log('Starting Request', request);
return request;
});
</script>
@stack('scripts')
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在我的其中一页中:
@extends('layouts.app')
@section('content')
<div>
<h1>Hello World</h1>
</div>
@endsection
@push('scripts')
<script>
async function test() {
const { data } = await http('/some-page');
// I'm getting a …Run Code Online (Sandbox Code Playgroud) 所以我开始使用Laravel,我发现它非常简单,现在我正在创建自己的宁静服务.我的问题是我不知道我是否正在进行href链接,但是它确实有效.这是代码:
<a href="{{URL::to('accounts/create')}}">Add user</a>
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我只渲染刀片:
public function create()
{
return view('accounts.create');
}
Run Code Online (Sandbox Code Playgroud)
因此,如果我单击添加用户链接,它将重定向到localhost:8080/accounts/create哪个工作正常.我的问题是,有更好的方法吗?就像我在路线文件中改变任何一样,我不会再改变href链接了吗?
我有一个有效的代码,但当我检查我的控制台时,我得到了SyntaxError: Unexpected token {这里的截图:
当line 58我studentController.js在这里查看它时console.log(error);.完整的代码是:
angular
.module('studentInfoApp')
.factory('Student', Student)
.controller('StudentsController', StudentsController)
.config(config);
function config($routeProvider) {
$routeProvider
.when('/', {
controller: 'StudentsController',
templateUrl: 'app/views/student-list.html'
})
}
function Student($resource) {
return $resource('/students/:id');
}
function StudentsController(Student, $scope, $http) {
$scope.inputForm = {};
$scope.students = null;
function initStudents() {
Student.query(function(data, headers) {
$scope.students = data;
$scope.studentsPanel = true;
console.log(data);
}, function (error) {
console.log(error);
});
}
initStudents();
$scope.addStudentForm = function() {
$scope.loading = true;
}
$scope.cancelAddStudent …Run Code Online (Sandbox Code Playgroud)