我使用的API是否正确? [英] Am I using api correctly?

查看:205
本文介绍了我使用的API是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里输入的形象描述

当我点击查看按钮,我就只看到第一个客户的记录?我如何获得特定客户的特定的ID,请解释一下我在细节和我使用codegniter这里是我的一些code的,我要添加..

AdminController.php

 < PHP
类AdminController扩展MY_Controller {
功能__construct()
{
    父:: __构造();
    如果($这个 - >!会话级>用户数据(ID)){
        返回重定向('的LoginController /指数');
    }
}
公共职能的仪表板()
{   $这个 - >负载>查看(管理/仪表盘);
}
公共职能orderhistory()
{
    $这个 - >负载>查看(管理/ order_history');
}
公共职能目录()
{
    $这个 - >负载>查看(管理/ catalouge');
}
公共职能admin_detail()
{
    $这个 - >负载>查看(管理/ admin_detail');
}
公共职能agent_detail()
{
    $这个 - >负载>查看(管理/代理');
}
公共职能为CustomerDetail()
{
    $这个 - >负载>查看(管理/客户);
}
公共职能paymenthistory()
{
    $这个 - >负载>查看(管理/支付');
}
公共职能view_order_history()
{
    $这个 - >负载>查看(管理/ view_order_history');
}
公共职能edit_order_history()
{
    $这个 - >负载>查看(管理/ edit_order_history');
}
公共职能分页($ CURRENT_PAGE)
{}
公共职能view_product_detail()
{
    $这个 - >负载>查看(管理/ view_product_detail');
}
公共职能edit_product_detail()
{
    $这个 - >负载>查看(管理/ edit_product_detail');
}
公共职能view_admin_detail()
{
    $这个 - >负载>查看(管理/ view_admin_detail');
}
公共职能edit_admin_detail()
{
    $这个 - >负载>查看(管理/ edit_admin_detail');
}
公共职能edit_agent_detail()
{
    $这个 - >负载>查看(管理/ edit_agent_detail');
}
公共职能view_agent_detail()
{
    $这个 - >负载>查看(管理/ view_agent_detail');
}
公共职能view_customer_detail()
{
    $这个 - >负载>查看(管理/ view_customer_detail');
}
公共职能edit_customer_detail()
{
    $这个 - >负载>查看(管理/ edit_customer_detail');
}
公共职能edit_payment_history()
{
    $这个 - >负载>查看(管理/ edit_payment_history');
}
公共职能view_payment_history()
{
    $这个 - >负载>查看(管理/ view_payment_history');
?}}>

View_order_history

 < D​​IV CLASS =容器>
    < D​​IV CLASS =超大屏幕>
        < H1>超大屏幕< / H1>
        < P>这是一个简单的英雄单位,调用格外注意功能的内容或信息的简单的超大屏幕式的组分LT; / P>
        < P><一类=BTN BTN-主要BTN-LG>了解详情< / A>< / P>
    < / DIV>
 < / DIV>


解决方案

既然你有相关的你实际上是在做什么没有code,这里有一些提示/想法:

在你的类,而不是做一堆,所有做同样的事情,我会建议使用 __()调用来的方法的超载的该类并保存自己吨的重复。通常我不会建议这一点,但在这种情况下,它是有道理的:

 类AdminController扩展MY_Controller {
    {
        受保护的$ args;
        公共职能__call($名称,$参数)
            {
                $计数=(空($参数)!);
                $这个 - > ARGS =($计数)?的$ args:假的;
                $这个 - >负载>查看(管理/ {$ NAME});
            }
    }

要使用,只需调用视图操作的名称:

  $ =测试新AdminController();
$ tester-> admin_detail();

在与表单,则可以使按钮与 ID 作为隐藏字段自己的按钮。我只想专注于客户阵列上的键 [0] 和子 [ 0] 。你,当然会做一个循环上的顾客[0] 数组以得到所有行:

 <! -  tester.php是您要发送的帖子关注页面。
我不知道你的实际页面被调用时,你有没有表示
- >
<形式的行动=/ tester.php的方法=后>
    <输入类型=文本名称=ID值=< PHP的echo $改编['客户'] [0] [0] ['身份证'];?>中/>
    <输入类型=提交名称=查看值=查看/>
    <输入类型=提交名称=删除价值=删除/>
    <输入类型=提交名称=编辑VALUE =编辑/>
< PHP
的foreach($改编['客户'] [0] [0]为$关键=> $值){
    回声$价值;
}
?>
< /表及GT;

当你点击查看按钮,并发布到焦点页面,你留下值的行的id,你可以用你的API将只是一个(presumably你知道如何让API来做到这一点?)。同样,你没有code贴到告诉你如何做任何事情真的,所以这只是一般。以下是该按钮就会产生。在 ID 将取决于你点击哪一行上更改。

 阵列

    [ID] => 1
    [查看] =>视图

when I click on view button I just only see record of first customer how do I get particular id of particular customer please explain me in detail and I am using codegniter here is some of my code where I want to add ..

AdminController.php

<?php
class AdminController extends MY_Controller {
function __construct()
{
    parent::__construct();
    if(!$this->session->userdata("id")) {
        return redirect('logincontroller/index');
    }
}
public function dashboard()
{

   $this->load->view('admin/dashboard');
}
public function orderhistory()
{
    $this->load->view('admin/order_history');
}
public function catalogue()
{
    $this->load->view('admin/catalouge');
}
public function admin_detail()
{
    $this->load->view('admin/admin_detail');
}
public function agent_detail()
{
    $this->load->view('admin/agent');
}
public function customerdetail()
{
    $this->load->view('admin/customers');
}
public function paymenthistory()
{
    $this->load->view('admin/payment');
}
public function view_order_history()
{
    $this->load->view('admin/view_order_history');
}
public function edit_order_history()
{
    $this->load->view('admin/edit_order_history');
}
public function pagination($current_page)
{

}
public  function view_product_detail()
{
    $this->load->view('admin/view_product_detail');
}
public  function edit_product_detail()
{
    $this->load->view('admin/edit_product_detail');
}
public  function view_admin_detail()
{
    $this->load->view('admin/view_admin_detail');
}
public  function edit_admin_detail()
{
    $this->load->view('admin/edit_admin_detail');
}
public  function edit_agent_detail()
{
    $this->load->view('admin/edit_agent_detail');
}
public  function view_agent_detail()
{
    $this->load->view('admin/view_agent_detail');
}
public  function view_customer_detail()
{
    $this->load->view('admin/view_customer_detail');
}
public  function edit_customer_detail()
{
    $this->load->view('admin/edit_customer_detail');
}
public  function edit_payment_history()
{
    $this->load->view('admin/edit_payment_history');
}
public  function view_payment_history()
{
    $this->load->view('admin/view_payment_history');
}}?>

View_order_history

<div class="container">
    <div class="jumbotron">
        <h1>Jumbotron</h1>
        <p>This is a simple hero unit, a simple jumbotron-style component for  calling extra attention to featured content or information.</p>
        <p><a class="btn btn-primary btn-lg">Learn more</a></p>
    </div>
 </div>

解决方案

Since you have no code relevant to what you are actually doing, here are some tips/ideas:

On your class, instead of making a bunch of methods that all do the same thing, I would suggest using __call() to overload the class and save yourself a ton of duplication. Normally I wouldn't suggest this, but in this case it makes sense:

class AdminController extends MY_Controller {
    {
        protected   $args;
        public  function __call($name,$args)
            {
                $count          =   (!empty($args));
                $this->args     =   ($count)? $args : false;
                $this->load->view("admin/{$name}");
            }
    }

To use, just call the name of the view action:

$tester =   new AdminController();
$tester->admin_detail();

When working with the form, you can make the buttons their own button with the id as a hidden field. I am just going to focus on the customer array on key [0] and subkey [0]. You, of course, would do a loop on the customer[0] array to get all rows:

<!-- tester.php is the page that you are sending the post to focus on.
I don't know what your actual page is called, you have not indicated
-->
<form action="/tester.php" method="post">
    <input type="text" name="id" value="<?php echo $arr['customer'][0][0]['id']; ?>" />
    <input type="submit" name="view" value="VIEW" />
    <input type="submit" name="delete" value="DELETE" />
    <input type="submit" name="edit" value="EDIT" />
<?php
foreach($arr['customer'][0][0] as $key => $value) {
    echo $value;
}
?>
</form>

When you click the VIEW button and post to the focus page, you are left with the row's id value which you can use your api to pull just that one (presumably you know how to get the API to do that?). Again you have no code posted to show how you do anything really, so this is just general. Here is what the button would produces. The id would change depending on which row you click on.

Array
(
    [id] => 1
    [view] => VIEW
)

这篇关于我使用的API是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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