小编Jar*_*ing的帖子

将字符串指向字符串

是否可以从指向字符串的指针获取字符串值?

我正在使用goopt包来处理标志解析,而包只返回*string.但我想使用这些值来调用地图中的函数.

举个例子.

var strPointer = new(string)
*strPointer = "string"

functions := map[string]func() {
    "string": func(){
        fmt.Println("works")
    },
}  

//Do something to get the string value

functions[strPointerValue]()
Run Code Online (Sandbox Code Playgroud)

你可以看到这里展示的问题http://play.golang.org/p/1s0-d-GO-L

pointers go

37
推荐指数
2
解决办法
3万
查看次数

Laravel 4 Eager Loading"Undefined Property"

为什么我不能在急切加载的Senario中访问该属性?

我正在尝试访问我的设施模型的照片位置.他们有很多:许多关系.当我使用加载设施信息时

$facilities = Facility::with('photos')->get();
Run Code Online (Sandbox Code Playgroud)

当我尝试访问时

foreach($facilities as $facility)
{
    echo $facility->photos->id;
}
Run Code Online (Sandbox Code Playgroud)

我明白了 Undefined property: Illuminate\Database\Eloquent\Collection::$id

如果我回应$facilities->photos我最终.

[{"id":"3",
"name":null,
"location":"facilities\/facility1.jpg\r",
"created_at":"2013-07-18 14:15:19",
"deleted_at":null,
"updated_at":null,
"pivot":{"facility_id":"5","photo_id":"3"}}]
Run Code Online (Sandbox Code Playgroud)

什么是访问此阵列中任何属性的最佳方法?

php laravel laravel-4

6
推荐指数
1
解决办法
5830
查看次数

Laravel 4中的用户身份验证

在Laravel 4中验证和登录用户时遇到问题.

我的登录表单指向此路线.

Route::post('login', function() {
    // get POST data
    $userdata = array(
        'username'      => Input::get('username'),
        'password'      => Input::get('password')
    );

    if ( Auth::attempt($userdata) )
    {
        // we are now logged in, go to home
        return Redirect::to('/');
    }
    else
    {
        // auth failure! lets go back to the login
        return Redirect::to('login')
            ->with('login_errors', true);
        // pass any error notification you want
        // i like to do it this way :)
    }
});
Run Code Online (Sandbox Code Playgroud)

在这一点上,一切似乎都很顺利.我被重定向到主页就好了,但是没有存储用户对象.如果我尝试访问任何用户函数,我会得到"试图获取非对象属性"错误.

这是我的用户模型

<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-4

4
推荐指数
1
解决办法
8998
查看次数

Laravel 4渴望加载多对多关系

尝试使用多对多关系对Laravel 4进行简单的热切加载.我的模特看起来像.

class Facility extends Eloquent {

    public function photos(){
            return $this->belongsToMany('Photo');
    }
}

class Photo extends Eloquent {

    public function facilities(){
            return $this->belongsToMany('Facility');
    }
}
Run Code Online (Sandbox Code Playgroud)

Tabes根据Laravel标准设置.当我尝试加载使用时

$facilities = Facility::with('Photo')->get();
Run Code Online (Sandbox Code Playgroud)

我最终得到了一个Laravel错误

Call to undefined method Illuminate\Database\Query\Builder::photo()
Run Code Online (Sandbox Code Playgroud)

有什么想法在这里做错了吗?

php laravel laravel-4

1
推荐指数
1
解决办法
1964
查看次数

标签 统计

laravel ×3

laravel-4 ×3

php ×3

go ×1

pointers ×1