网址上做Laravel要求 [英] URL to do request on Laravel

查看:101
本文介绍了网址上做Laravel要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但我还没有找到任何办法解决它。我的项目使用的队友的 Laravel 写道:我们的项目的服务器端。我的工作是开发Android应用程序。我知道如何发送和Android之间的PHP JSON接受。但是,我不知道很多关于Laravel。所以我不知道我应该使用哪个URL发送/接收JSON。

要哪个URL应该我送我的JSON使用以下post_list()方法下的文件my_application_name /应用/控制器/ menucategory.php?

 < PHP类MenuCategory_Controller扩展Base_Controller {    公共$宁静= TRUE;    公共职能post_list(){
        $类= MenuCategory ::所有();
        $猫= NULL;
        的foreach($类别,$类){
            $猫[] =数组(
                'ID'=> $分类 - > ID,
                '名'=> $分类 - >名
            );
        }
        返回响应:: JSON(阵列('类'=> $猫));
    }
}?>


解决方案

由于控制器是宁静的,你只需要指向控制器的名称,方法的名称(不动作)

例如,在这种情况下, menucategory /列表因为它是MenuCategory控制器,你列表

在此的更多信息可以在这里laravel文档中可以看出: http://laravel.com /文档/控制器#宁静控制器

This may be a silly question, but I haven't find any way to solve it yet. My project mate wrote server side of our project using Laravel. My job is to develop Android App. I know how to send and receive JSON between Android and PHP. However, I don't know much about Laravel. So I don't know which URL should I use to send/receive JSON.

To which URL should I send my JSON to use the following post_list() method under the file my_application_name/application/controllers/menucategory.php ?

<?php

class MenuCategory_Controller extends Base_Controller {

    public $restful = true;

    public function post_list() {
        $categories = MenuCategory::all();
        $cat = null;
        foreach ($categories as $category) {
            $cat[] = array(
                'id' => $category->id,
                'name' => $category->name
            );
        }
        return Response::json(array('categories' => $cat));
    }
}

?>

解决方案

Since the controller is restful, you just need to point to the name of the controller, and the name of the method (without the action)

e.g., in this case, you post to menucategory/list since it's the MenuCategory controller, and you post to list

More information on this can be seen in the laravel docs here: http://laravel.com/docs/controllers#restful-controllers

这篇关于网址上做Laravel要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆