我很好奇,如果有任何人使用Laravel,因为版本3在cookie名称中有下划线时遇到了在各种版本的IE中设置cookie的问题.
我的项目(基于CI的电子商务网站)遇到了这个问题.解决了问题,删除了cookie名称中的下划线.
虽然我目前正在将项目移植到Laravel,但我只是想检查是否应该从会话cookie中删除下划线.
我来自CodeIgniter到Laravel.
那么,使用自动路由到所有控制器是一个坏主意吗?
Route::controller(Controller::detect());
Run Code Online (Sandbox Code Playgroud)
我应该使用它而不是在routes.php中创建路由吗?
在尝试实现基于Laravel长度的验证时
'password' => array(
'required',
'alpha_dash',
'Min:7'
)
Run Code Online (Sandbox Code Playgroud)
并在我的视图中输出错误消息
{{
$errors->first(
'password',
'<span class="error">:message</span>'
)
}}
Run Code Online (Sandbox Code Playgroud)
我明白了
Unhandled Exception
Message:
Array to string conversion
Location:
_avalog\laravel\messages.php on line 188
Stack Trace:
#0 _avalog\laravel\laravel.php(42): Laravel\Error::native(8, 'Array to string...', '_avalog...', 188)
#1 [internal function]: Laravel\{closure}(8, 'Array to string...', '_avalog...', 188, Array)
#2 _avalog\laravel\messages.php(188): str_replace(':message', Array, 'get('password', 'get()
Run Code Online (Sandbox Code Playgroud)
调试,似乎是真的.如果我print_r( $validation );
Laravel\Validator Object (
[attributes] => Array (
[username] => fred
[email] =>
[password] => asd
[csrf_token] => DWg3CUfqtMZkIRfyZXNEqygvWUHsGS9SQMue2V4S
)
[errors] => …Run Code Online (Sandbox Code Playgroud) 我有一个基本控制器,有一个方法可以将Twitter提要返回给我的视图.
我想在视图中将其从页面视图移动到默认刀片,以减少冗余,因为它将出现在网站范围内.如何将数据从基本控制器传递到刀片?
我可以从页面控制器发送到我的视图,如下所示:
public function get_index()
{
..................
$this->layout->nest('content', 'home.index', array(
'tweets' => $this->get_tweet()
));
}
Run Code Online (Sandbox Code Playgroud)
并在视图中,输出如下:
if ($tweets)
{
foreach ($tweets as $tweet)
{
..............
Run Code Online (Sandbox Code Playgroud)
我想在default.blade.php和我的Base_Contoller中做所有这些:
<?php
class Base_Controller extends Controller {
/**
* Catch-all method for requests that can't be matched.
*
* @param string $method
* @param array $parameters
* @return Response
*/
public function __call($method, $parameters)
{
return Response::error('404');
}
public function get_tweet()
{
...........
return $tweets;
}
}
Run Code Online (Sandbox Code Playgroud)
这怎么可能?
////////////////////// UPDATE /////////////////////////// //
应用程序/模型/ tweets.php …
我正在使用Laravel 3,我在用户评论中使用AJAXing.我们正在为此评论添加图像,我似乎无法获取文件数据.当我将processData设置为false时,我也无法访问其他数据,例如评论和隐私.任何见解?
var commentforms = $('form.compose');
commentforms.on('submit', function(e){
e.preventDefault();
var file = document.getElementById('file_input').files[0];
$.ajax({
type: 'POST',
url: '/issue/comment/' + issue_id,
processData: false,
data: {
side: side,
comment: comment,
privacy: privacy,
file: file,
},
success: function(response){
console.log(response);
new_comment = comment_template(response);
updateSide(new_comment);
},
});
Run Code Online (Sandbox Code Playgroud) 我在使用Redirect::route()Laravel 后尝试在URL的末尾添加斜杠.我尝试了很多例子,但无法找到答案.
这是我到目前为止:
routes.php:
Route::get('/', function() {
return Redirect::route('login');
});
Route::get('/login/', array(
'as' => 'login',
'uses' => 'Controller@login'
));
Run Code Online (Sandbox Code Playgroud)
Controller.php:
public function login()
{
return 'Login page';
}
Run Code Online (Sandbox Code Playgroud)
当我去htdocs/laravel_project/,我被重定向到htdocs/laravel_project/login但我希望它是htdocs/laravel_project/login/我想在URL的末尾添加斜杠.如果我手动在URL处输入斜杠,它就会按照我想要的方式进行.
我有另一个系统将data.json文件放在我的Laravel站点/文件夹结构的某个地方.
我只希望Laravel能够读取json文件(即用户无法通过在浏览器中输入url来查看它).
这个文件应该放在哪里?
我目前在应用程序/模型文件夹或应用程序/ [新文件夹]之间徘徊.我的webroot设置为公用文件夹,因此您无法通过浏览器访问应用程序文件夹.
如果它在那里,我假设我将能够在PHP内读取它而不是javascript(这没关系).
这是非常标准的登录功能和验证,可以很好地工作.但我还想检查用户是否处于活动状态.我在users表中设置了一个列,其中'active'设置为0或1.
public function post_login()
{
$input = Input::all();
$rules = array(
'email' => 'required|email',
'password' => 'required',
);
$validation = Validator::make($input, $rules);
if ($validation->fails())
{
return Redirect::to_route('login_user')
->with_errors($validation->errors)->with_input();
}
$credentials = array(
'username' => $input['email'],
'password' => $input['password'],
);
if (Auth::attempt($credentials))
{
// Set remember me cookie if the user checks the box
$remember = Input::get('remember');
if ( !empty($remember) )
{
Auth::login(Auth::user()->id, true);
}
return Redirect::home();
} else {
return Redirect::to_route('login_user')
->with('login_errors', true);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这样的事了:
$is_active = Auth::user()->active;
if …Run Code Online (Sandbox Code Playgroud) 我正在与Laravel 3合作.我想在网站上建立一个报告页面.我有一些视图表如下:
+---------+-----------------+-------+
| user_id | username | total |
+---------+-----------------+-------+
| 1 | user | 12 |
| 2 | admin | 3 |
| 3 | user2 | 1 |
| 4 | user3 | 1 |
+---------+-----------------+-------+
Run Code Online (Sandbox Code Playgroud)
我想在图表视图中显示数据.制作它的最佳方法是什么?
我需要学习如何使用Laravel中的cron作业.我可以看到文档没有指定这部分.我找到了一个教程,但它是关于Laravel-3的.你可以给我一些关于如何安排每天运行一次cron工作的建议吗?吗?有没有关于这个问题的教程?
到目前为止,我的代码如下:
JobDaemon.php:
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class JobDaemon extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'job-daemon';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Get all recent jobs once a day.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return void
*/ …Run Code Online (Sandbox Code Playgroud) laravel-3 ×10
laravel ×9
php ×6
laravel-4 ×3
ajax ×1
charts ×1
if-statement ×1
javascript ×1
jquery ×1
validation ×1