我在(梦幻般的)Laravel PHP框架上使用工匠时遇到了致命的错误.
我最近下载了Laravel的v3.2.1,并尝试在artisan所在的目录中运行以下命令行:
php artisan key:generate
Run Code Online (Sandbox Code Playgroud)
这应该在我的applications/application.php文件中为我创建一个随机密钥.(有关此命令的特定参考,请参阅http://laravel.com/docs/artisan/commands.)
但是,当我从shell运行此命令时,我收到以下错误:
Warning: chdir(): No such file or directory (errno 2) in /home/[USERNAME REMOVED]/websites/[DIRECTORY REMOVED]/htdocs/dev/sb4/paths.php on line 62
Parse error: syntax error, unexpected T_STRING in /home/[USERNAME REMOVED]/websites/[DIRECTORY REMOVED]/htdocs/dev/sb4/laravel/core.php on line 1
Run Code Online (Sandbox Code Playgroud)
这就是paths.php第62行的内容:
chdir(__DIR__);
Run Code Online (Sandbox Code Playgroud)
这是core.php的第1行:
<?php namespace Laravel;
Run Code Online (Sandbox Code Playgroud)
我的问题是:是否有任何特定的环境,目录或其他权限我应该修改以使工匠启动并运行.
一点背景:
我的环境:
我的根目录:(括号中的权限)
如果我的相关设置有任何其他详细信息,请告知我们.我真的不确定在解决此问题时有什么帮助.
-
更新:我还将此问题发布到Laravel的GitHub问题跟踪器.(https://github.com/laravel/laravel/issues/820)
我有一个旧库(phpquery),我想在我的项目中包含它.我把它放在供应商中,但它不起作用,因为它不符合PSR-0.我不希望它为每个请求加载,所以我没有把require内部bootstrap autoload.php.
我甚至不知道,我怎么能得到应用程序的根源.跑步path()给了我一个URL,而不是我想要的.
那我该怎么办呢?
我正在尝试访问当前控制器的名称和当前方法,以将其作为变量传递给我的视图.我已经尝试了几种方法,我在网上发现但是它们没有用,所以我认为它们是用于Laravel 3.
这是我尝试过的
Request::$route->controller
Run Code Online (Sandbox Code Playgroud)
给
Access to undeclared static property: Illuminate\Support\Facades\Request::$route
Run Code Online (Sandbox Code Playgroud)
和
Request::route()->controller
Run Code Online (Sandbox Code Playgroud)
给
Call to undefined method Illuminate\Http\Request::route()
Run Code Online (Sandbox Code Playgroud) 我正在使用像这样的laravel查询生成器.
$col1 = Input::get('col1','');
$col2 = Input::get('col2','');
$result = DB::table('table1')
->select('id', 'col1', 'col2', 'col3')
->whereRaw("col1 like '%?%'", [$col1])
->whereRaw("col2 like '%?%'", [$col2])
->orderBy($orderBy, $orderType) //orderBy=col1, ordeyType=ASC
->skip($ofset)->take($limit) //$ofser=0, $limit=10
->get();
Run Code Online (Sandbox Code Playgroud)
我一无所获.如果我使用toSql()函数.我这样得到这个SQL
select `id`, `col1`, `col2`, `col3`
from `table1` where col1 like '%?%' and col2 like '%?%'
order by `col1` ASC limit 10 offset 0
Run Code Online (Sandbox Code Playgroud)
问号不应该存在.它必须用值替换它们.我用这段代码来调试它.
Log::info(var_export(DB::getQueryLog(), true));
Run Code Online (Sandbox Code Playgroud)
日志看起来像这样
2 =>
array (
'query' => 'select `id`, `col1`, `col2`, `col3` from `table1` where col1 like \'%?%\' and col2 like \'%?%\' order …Run Code Online (Sandbox Code Playgroud) 我在http://codebright.daylerees.com/上关注Laravel 4教程.
在codebright.daylerees.com/controllers中,您可以看到RESTful Controllers教程
我到达了高级路由教程codebright.daylerees.com/advanced-routing.
有一个示例代码可以使用Route :: get和命名路由.然后我尝试使用Route :: controller来创建具有命名路由的RESTful URI.然后,我尝试将此代码编写为routes.php:
Route::controller('my/very/long/article/route2', array(
'as'=>'article2',
'uses'=>'Blog\Controller\Article'
));
Run Code Online (Sandbox Code Playgroud)
这是我的controller/Article.php代码:
<?php
namespace Blog\Controller;
use View;
use BaseController;
class Article extends BaseController
{
public function getCreate()
{
return View::make('create');
}
public function postCreate()
{
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试访问我的/ very/long/article/route2/create时,它显示错误
ErrorException
Array to string conversion
…\vendor\laravel\framework\src\Illuminate\Routing\Controllers\Inspector.php
Run Code Online (Sandbox Code Playgroud)
知道如何使用RESTful实现到控制器的命名路由吗?
直到最近,当我跑步时,我的项目一直很好sudo composer self-update.Composer已成功更新,但我无法再迁移(php artisan migrate).这是我得到的错误:
PHP Fatal error: Class 'Patchwork\Utf8\Bootup' not found in /Applications/MAMP/htdocs/ThumbsUp/bootstrap/autoload.php on line 46
Run Code Online (Sandbox Code Playgroud)
我已经跑composer update和composer install,仍然错误仍然存在.为什么不能在这之后找到这门课self-update?
让我们举两个例子.
示例1(存储库模式)
接口
interface FooInterface {
public function all();
}
Run Code Online (Sandbox Code Playgroud)
模型(在松散的术语中使用它)
class FooModel implements FooInterface {
public function all()
{
return DB::('sometable')->get();
}
}
Run Code Online (Sandbox Code Playgroud)
服务提供者
class FooServiceProvider extends ServiceProvider {
public function register()
{
$this->app->bind(
'Foo\FooInterface',
'Foo\FooModel'
);
}
Run Code Online (Sandbox Code Playgroud)
配置/ app.php
'providers' => array(
// --
'Foo\FooServiceProvider'
),
Run Code Online (Sandbox Code Playgroud)
而在最后的控制器:
use Foo\FooInterface as Model;
public function __construct(Model $model)
{
$this->model = $model;
}
Run Code Online (Sandbox Code Playgroud)
现在我可以访问方法了$this->model->all().那很棒!让我们看看第二个例子.
例2:
控制器:
public function __construct() …Run Code Online (Sandbox Code Playgroud) php dependency-injection repository-pattern laravel laravel-4
出于某种原因,我的生产laravel应用程序认为它是在本地环境中.
/var/www/appname/.env.php
<?php
return
[
'APP_ENV' => 'production',
'DB_HOST' => 'HIDDEN',
'DB_NAME' => 'HIDDEN',
'DB_PASSWORD' => 'HIDDEN'
];
Run Code Online (Sandbox Code Playgroud)
/var/www/appname/bootstrap/start.php
$env = $app->detectEnvironment(function()
{
return getenv('APP_ENV') ?: 'local';
});
Run Code Online (Sandbox Code Playgroud)
/var/www/appname/app/config/database.php
...
...
'mysql' => array(
'driver' => 'mysql',
'host' => getenv('DB_HOST'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'lar_',
),
...
...
Run Code Online (Sandbox Code Playgroud)
sudo php artisan env (通过SSH)
`Current application environment: local
Run Code Online (Sandbox Code Playgroud)
php artisan tinker 然后 getenv('DB_NAME')
$ php artisan tinker
[1] …Run Code Online (Sandbox Code Playgroud) environment-variables production-environment laravel laravel-4
更新:
当我在Laravel 4工作时,我的退出操作有问题,但是在laravel 4.1中我有这个错误:
Missing argument 2 for Illuminate\Database\Eloquent\Model::setAttribute(),
called in
C:\Users\mohammed\workspace\mylittlebiz\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php on line 2432 and defined
Run Code Online (Sandbox Code Playgroud)
这是我的行动:
public function doLogout()
{
Auth::logout(); // log the user out of our application
return Redirect::to('login'); // redirect the user to the login screen
}
Run Code Online (Sandbox Code Playgroud)
这是我的模特:
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
protected $hidden = array('password');
/**
* Get …Run Code Online (Sandbox Code Playgroud) 我有以下RegEx使用和工作:
/\B@(@?\w+(?:::\w+)?)([ \t]*)(\( ( (?>[^()]+) | (?3) )* \))?/x
这个字符串@extends('template', 'test')正确分组并给我我需要的地方.
问题是如果字符串在引号内包含一个未闭合的括号 - 它将失败:
@extends('template', 'te)st')给出@extends('template', 'te)输出
如何告诉此RegEx忽略引号内的括号('或者")
以下是问题的RegExr演示:http://regexr.com/v1?396ci
这是一个应该能够通过的字符串列表:
@extends('template', 'test') // working
@extends('template', $test) // working
@extends('template', 'te()st') // working
@extends('template', 'te)st') // broken
@extends('template', 'te())st') // broken
@extends('template', 'te(st') // broken
@extends('template', 'test)') // broken
@extends('template', '(test') // broken
Run Code Online (Sandbox Code Playgroud)
我把它缩小了 - 我想我需要能够说出来
(
\( <-- only if not inside quotes
(
(?>[^()]+) | (?3)
)*
\) …Run Code Online (Sandbox Code Playgroud) laravel ×9
laravel-4 ×7
php ×7
autoload ×1
composer-php ×1
laravel-3 ×1
regex ×1
regex-group ×1
rest ×1