【问题标题】:How to get passed data laravel?laravel 如何获取传递的数据?
【发布时间】:2018-02-26 00:21:09
【问题描述】:

我使用在Laravel 上运行的October CMS 并且有一个/api/:page_id 页面,该页面现在只返回一个链接。我的目标是在打开该页面时将任何页面的id 发送到api。这是/api/:page_id 的代码:

function onInit()
{
    $page_id = $this->param('page_id'); 
    $pageURL =  "http://$_SERVER[HTTP_HOST]/".$page_id;
    echo "Your full link is : <br><a href=\"".$pageURL."\">Link</a>";

}

我只是不知道如何将参数发送到api。例如,这是我要用于此的页面中的 sn-p:

function onStart()
{
  $this->page['baseFileName']);
  /* code to send baseFileName to api page */
}

【问题讨论】:

  • 请提供更多信息

标签: php laravel parameter-passing octobercms


【解决方案1】:

在 Laravel 中,您有一个 routes 文件夹,其中包含 api.php 中 api 请求的路由。在此处编辑您的基本路线,例如 -

Route::get("/{page_id}", "MyAPIController@onStart");

您的请求处理方法onStart 就是这样-

function onStart(Request $request, $page_id)
{
    // $page_id variable holds the page id
    // Laravel throws an internal error if there is no id parameter in the url
}

然后你可以发送一个get请求到urlhttp://myurl.com/&lt;page_id&gt;

【讨论】:

    猜你喜欢
    • 2017-09-03
    • 2015-03-09
    • 2021-01-07
    • 2015-03-03
    • 2019-09-30
    • 2018-01-11
    • 1970-01-01
    • 2016-09-01
    • 2022-09-24
    相关资源
    最近更新 更多