我有一个基本的PHP应用程序,其中用户登录存储在HTTP会话中.该应用程序有一个主模板,比如index.html,可以使用ngView切换子视图,就像这样
<body ng-controller='MainCtrl'>
<div ng-view></div>
</body>
Run Code Online (Sandbox Code Playgroud)
现在,这个主模板可以通过基本的PHP控件保护,但我有子模板(即用户列表,添加用户,编辑用户等),这些是普通的html文件,根据我的路由设置从angular包含.
虽然我能够检查auth与http服务的请求有什么关系,但是一个用户能够导航到子模板URL并访问它.我怎样才能防止这种情况发生?
我正在使用这个插件https://github.com/ericmbarnard/Knockout-Validation,我正在尝试验证动态加载的对象.
使用Javascript:
function VM() {
var self = this;
// This is a static observable, just to ensure that basic validation works fine.
self.static = ko.observable();
self.static.extend({required: true});
// This is the observable that will be updated to my model instance.
self.person = ko.observable({});
// This is an handler for manual trigger.
// I'm not even sure this is needed.
self.a = function(){
self.errors.showAllMessages();
self.staticErrors.showAllMessages();
}
// Here i'm loading current person from somewhere, i.e. a rest service. …
Run Code Online (Sandbox Code Playgroud) 如何在L4中更改PHP error_reporting?
我发现这个http://forums.laravel.io/viewtopic.php?id=6072,但它是关于L3而我无法弄清楚如何实现同样的目标,即阻止应用程序在php上抛出异常E_NOTICE.
我知道我能做到这一点
Route::get('foo/bar', array('before' => 'filter', 'uses' => 'Controller@bar'));
Run Code Online (Sandbox Code Playgroud)
应用路由一些过滤器.我也知道Route :: group()方法.无论如何,如果我想以这种方式定义控制器
Route::controller('foo/{id}/bar', 'Controller');
Run Code Online (Sandbox Code Playgroud)
我不能将数组作为第二个参数传递.
问题:如何将过滤器应用于以下路线?
Route::controller('foo/{id}/bar', 'Controller');
Run Code Online (Sandbox Code Playgroud)
===编辑
我想在我的route.php中编码,而不是在控制器构造函数中.
这是我的主要应用程序(app.js)
(function(ng, module) {
module.config(['$stateProvider', '$urlRouterProvider', function( $stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise("app");
$stateProvider.state('login', {
url: 'login',
templateUrl: '/assets/templates/pages/login.html'
}).state('root', {
url: '',
templateUrl: '/assets/templates/pages/index.html'
});
}]);
}) (angular, angular.module('myapp', ['ui.router', 'myapp.submodule']));
Run Code Online (Sandbox Code Playgroud)
这是子模块(submodule.js)
(function(ng, module) {
module.config(['$stateProvider', function($stateProvider){
$stateProvider.state('root.substate', {
url: 'todo/{type}',
templateUrl: '/assets/app/todo/todo.html',
controller: function($stateParams, $scope) {
// Do stuff.
}
});
}]);
}) (angular, angular.module('myapp.submodule', ['ui.router']));
Run Code Online (Sandbox Code Playgroud)
预期的行为将是
这工作正常.
但是,如果我刷新页面,状态不会被激活,我会被发送回"app".为什么?
我已经添加
"laravel/socialite": "~2.0"
Run Code Online (Sandbox Code Playgroud)
作为作曲家依赖项,我已经在我的中添加了服务提供者,config/app.php
就像这样
'providers' => [
// more providers
'Laravel\Socialite\SocialiteServiceProvider'
]
Run Code Online (Sandbox Code Playgroud)
然后,当我访问任何应用程序路由时,我遇到了此Class 'Laravel\Socialite\SocialiteServiceProvider' not found
异常。
看看我的,vendor/composer/autoload_psr4.php
我发现没有社交名流映射 - 我跑过composer update
不止一次composer dump-autoload
。
怎么了?
我有一个包含多对多类别和标签的内容模型。类别和标签使用布尔tag
标志存储在同一个表中:
category_id | name | tag
1 | Products | 0
2 | bestsellers | 1
Run Code Online (Sandbox Code Playgroud)
我的内容模型具有如此定义的条件关系:
public function categories() {
return $this->belongsToMany('Foothing\Content\Z\Entities\Category\Eloquent\Category', 'content_content_categories', 'cid', 'tid')->where('tag', false);
}
public function tags() {
return $this->belongsToMany('Foothing\Content\Z\Entities\Category\Eloquent\Category', 'content_content_categories', 'cid', 'tid')->where('tag', true);
}
Run Code Online (Sandbox Code Playgroud)
当tag
标志在读取操作上正常工作时,即
$categories = Content::find(1)->categories;
$tags= Content::find(1)->tags;
Run Code Online (Sandbox Code Playgroud)
它在sync
操作中没有按预期工作,实际上是以下代码
$content->categories()->sync(1, 2, 3);
Run Code Online (Sandbox Code Playgroud)
将同步整个表格,无论tag
标志如何:标签将被销毁,我的内容将仅与类别 1、2、3 相关。
这种方法有什么不好的地方吗?
我的目标是编写一些可重用的代码来渲染基本的导航栏,因为这将是一个非常重复的任务.以下功能是我的第一个目标:
这是我的第一次尝试.我希望标记是这样的
<ul data-bind='foreach: pages'>
<li>
<!--
[1]
Here a toggler is needed for active/no-active status,
i.e. a class binding.
-->
<a data-bind='html: caption, click: $data.load'></a>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
每个页面项应该看起来像这样
function PageItem(id, caption) {
this.id= id;
this.caption = caption;
this.page = pager.page.find(id);
this.load = function() {
// [2]
// Code here to trigger page load,
// i.e. this.page.async(someCallback, this.id);
}
this.active = function() {
// [3]
return this.page.isVisible();
}
}
Run Code Online (Sandbox Code Playgroud)
使用目标:
function VM() {
var self = this; …
Run Code Online (Sandbox Code Playgroud) 我有一个依赖于 UserManager 的控制器。这是控制器构造函数:
public function __construct(UserManager $manager) {
$this->manager = $manager;
}
Run Code Online (Sandbox Code Playgroud)
这是测试代码。
public function test_something() {
$this->withoutMiddleware();
// Setup Input.
$user = ['email' => 'foo@bar.baz', 'password' => 'pass', 'accessLevel' => 'admin'];
// Setup expectations.
$mock = \Mockery::mock("Users\UserManager")->shouldReceive('foo');
// Bind to container... not sure whether this is needed.
$this->app->instance("Users\UserManager", $mock);
// Call action.
$this->call('POST', 'api/v1/temp/users', ['user' => $user]);
}
Run Code Online (Sandbox Code Playgroud)
我对该方法设置了期望foo
,该方法不存在,因此不会在任何地方调用,但是我的测试不会失败。
为什么?
检查这个HTML代码
<p>test</p>
<p>
<ul>
<li>
<span style=\"line-height: 1.42857;\">1
</span>
<br>
</li>
<li>
<span style=\"line-height: 1.42857;\">2
</span>
<br>
</li>
<li>
<span style=\"line-height: 1.42857;\">3
</span>
<br>
</li>
<li>
<span style=\"line-height: 1.42857;\">4
</span>
<br>
</li>
</ul>
<p>
<span style=\"line-height: 20px;\">more text
</span>
</p>
</p>
Run Code Online (Sandbox Code Playgroud)
出于某种原因,之前和之后的<ul>
空<p>
它被呈现(我已经尝试过Chrome和FF至今).
在这里检查这个plunker并尝试检查结果,你会看到这样的东西
<body>
<p>test
</p>
<p> <----------THIS
</p>
<ul>
<li>
<span style="\"line-height:" 1.42857;\"="">1
</span>
<br>
</li>
<li>
<span style="\"line-height:" 1.42857;\"="">2
</span>
<br>
</li>
<li>
<span style="\"line-height:" 1.42857;\"="">3
</span>
<br>
</li>
<li>
<span …
Run Code Online (Sandbox Code Playgroud) laravel ×5
php ×5
javascript ×3
angularjs ×2
knockout.js ×2
laravel-4 ×2
laravel-5 ×2
composer-php ×1
eloquent ×1
html ×1
laravel-5.1 ×1
mockery ×1
pagerjs ×1
phpunit ×1