试图将个人标题和元描述应用到我的网站页面,但我不确定我尝试的方式是否非常干净.
master.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>{{ $title }}</title>
<meta name="description" content="{{ $description }}">
</head>
Run Code Online (Sandbox Code Playgroud)
个人页面
@extends('layouts.master')
<?php $title = "This is an individual page title"; ?>
<?php $description = "This is a description"; ?>
@section('content')
Run Code Online (Sandbox Code Playgroud)
我觉得这是一种快速而肮脏的方式来完成工作,是否有更简洁的方法?
在最终让我的愚蠢简单测试通过后,我感觉我没有正确地做到这一点.
我有一个SessionsController,负责显示登录页面并记录用户.
我决定不使用外观,这样我就不必延长Laravel的TestCase并在单元测试中获得性能.因此,我已通过控制器注入所有依赖项,如此 -
SessionsController - 构造函数
public function __construct(UserRepositoryInterface $user,
AuthManager $auth,
Redirector $redirect,
Environment $view )
{
$this->user = $user;
$this->auth = $auth;
$this->redirect = $redirect;
$this->view = $view;
}
Run Code Online (Sandbox Code Playgroud)
我已经完成了必要的变量声明和使用命名空间,我不打算将其包括在内,因为它是不必要的.
create方法检测用户是否被授权,如果是,则将其重定向到主页,否则显示登录表单.
SessionsController - 创建
public function create()
{
if ($this->auth->user()) return $this->redirect->to('/');
return $this->view->make('sessions.login');
}
Run Code Online (Sandbox Code Playgroud)
现在进行测试,我是新手,所以请耐心等待.
SessionsControllerTest
class SessionsControllerTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
Mockery::close();
}
public function test_logged_in_user_cannot_see_login_page()
{
# Arrange (Create mocked versions of dependencies)
$user = Mockery::mock('Glenn\Repositories\User\UserRepositoryInterface');
$authorizedUser = Mockery::mock('Illuminate\Auth\AuthManager');
$authorizedUser->shouldReceive('user')->once()->andReturn(true);
$redirect …Run Code Online (Sandbox Code Playgroud) 我正在尝试为用户创建一种搜索网站上所有产品的方法.当他们搜索"burton滑雪板"时,我只想在结果中出现带有品牌burton的滑雪板.但如果他们只搜索"burton",那么所有带有品牌burton的产品都应该出现.
这是我试图写的但由于多种原因而无法工作.
控制器:
public function search(){
$input = Input::all();
$v= Validator::make($input, Product::$rules);
if($v->passes())
{
$searchTerms = explode(' ', $input);
$searchTermBits = array();
foreach ($searchTerms as $term) {
$term = trim($term);
if (!empty($term)){
$searchTermBits[] = "search LIKE '%$term%'";
}
}
$result = DB::table('products')
->select('*')
->whereRaw(". implode(' AND ', $searchTermBits) . ")
->get();
return View::make('layouts/search', compact('result'));
}
return Redirect::route('/');
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试为此stackoverflow.com问题重新创建第一个解决方案
我发现的第一个问题是我试图爆炸$input,但它已经是一个数组.所以我不确定如何解决这个问题.我写的方式->whereRaw(". implode(' AND ', $searchTermBits) . "),我肯定是不正确的.我不知道如何解决这些问题,任何见解或解决方案都将受到高度赞赏.
我正在尝试制作一个自定义指令,因为我提出的第一个解决方案有效,但它似乎很乱.
当tr元素具有mouseenter时,我想显示铅笔图标,当mouseleave出现时,铅笔图标应该再次隐藏.
第一个解决方案:(这有效)
<tr ng-mouseenter="hoverEdit = !hoverEdit" ng-mouseleave="hoverEdit = !hoverEdit" ng-repeat="user in users">
<td>{{user.first_name}}</td>
<td>{{user.last_name}}</td>
<td>{{user.email}}</td>
<td><i ng-show="hoverEdit" class="fa fa-pencil"></i></td>
<td><button class="btn btn-danger" ng-click="delete(user)">Delete</button></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我认为ng-mouseenter并且ng-mouseleave似乎使tr元素混乱,所以我想创建一个指令......这是我尝试过的
指令解决方案(不起作用)
Users.directive('showpencilhover', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.on('mouseenter', function() {
hoverEdit == !hoverEdit
});
element.on('mouseleave', function() {
hoverEdit == !hoverEdit
});
}
}
});
Run Code Online (Sandbox Code Playgroud)
我相信问题是我不能只引用hoverEdit,所以我不确定如何使这项工作.谢谢你的建议!
我正在尝试用jQuery设置一组按钮.对于活动按钮,我希望它看起来不同,因此用户知道它的活动状态.
这些按钮是使用php foreach循环生成的,如下所示:
foreach($result as $row){
echo "<a class='linkClass linkStyle' onclick='javascript:swapContent(" . $row['Count'] . "," . $row['ProductID'] . ");'>" . $row['Count'] . "</a>";
}
Run Code Online (Sandbox Code Playgroud)
我正试图用这个jQuery点击功能来设置它:
$(document).ready(function() { $('.linkClass').eq(0).click(); })
$(".linkStyle").click(function() {
$(this).css("background","#258ace");
$(this).css("border-top-color", "#258ace");
});
Run Code Online (Sandbox Code Playgroud)
第一个按钮点击第一个按钮,以便当用户访问该页面时,他们知道正在显示哪些活动内容.我的问题是,当按下另一个按钮时,样式将应用于它,并且它们也保留在另一个按钮上.我需要一种方法来在按下另一个按钮时重置或删除linkStyles类,并且只将它应用于当时处于活动状态的任何按钮.
laravel ×3
php ×3
javascript ×2
laravel-4 ×2
angularjs ×1
blade ×1
html ×1
jquery ×1
mysql ×1
unit-testing ×1