网址上做Laravel要求上做、网址、Laravel

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

这可能是一个愚蠢的问题,但我还没有找到任何办法解决它。我的项目使用的队友的 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(阵列('类'=> $猫));    }}?> 
Laravel Kit下载 在线应用管理 v2.0.1 官方版

解决方案

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

例如,在这种情况下, 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

阅读全文

相关推荐

最新文章