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

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

问题描述

当我点击查看按钮时,我只看到第一个客户的记录我如何获得特定客户的特定 id 请详细解释我,我正在使用 codegniter 这里是我想添加的一些代码..

AdminController.php

session->userdata("id")) {返回重定向('登录控制器/索引');}}公共功能仪表板(){$this->load->view('admin/dashboard');}公共函数 orderhistory(){$this->load->view('admin/order_history');}公共函数目录(){$this->load->view('admin/catalouge');}公共函数 admin_detail(){$this->load->view('admin/admin_detail');}公共函数 agent_detail(){$this->load->view('admin/agent');}公共函数 customerdetail(){$this->load->view('admin/customers');}公共函数支付历史(){$this->load->view('admin/payment');}公共函数 view_order_history(){$this->load->view('admin/view_order_history');}公共函数 edit_order_history(){$this->load->view('admin/edit_order_history');}公共函数分页($current_page){}公共函数 view_product_detail(){$this->load->view('admin/view_product_detail');}公共函数 edit_product_detail(){$this->load->view('admin/edit_product_detail');}公共函数 view_admin_detail(){$this->load->view('admin/view_admin_detail');}公共函数 edit_admin_detail(){$this->load->view('admin/edit_admin_detail');}公共函数 edit_agent_detail(){$this->load->view('admin/edit_agent_detail');}公共函数 view_agent_detail(){$this->load->view('admin/view_agent_detail');}公共函数 view_customer_detail(){$this->load->view('admin/view_customer_detail');}公共函数 edit_customer_detail(){$this->load->view('admin/edit_customer_detail');}公共函数 edit_payment_history(){$this->load->view('admin/edit_payment_history');}公共函数 view_payment_history(){$this->load->view('admin/view_payment_history');}}?>

View_order_history

<div class="jumbotron"><h1>Jumbotron</h1><p>这是一个简单的英雄单元,一个简单的超大屏幕风格的组件,用于引起对特色内容或信息的额外关注.</p><p><a class="btn btn-primary btn-lg">了解详情</a></p>

解决方案

由于您没有与实际操作相关的代码,这里有一些提示/想法:

在你的课堂上,我建议你使用 __call()重载这个类,而不是制作一堆都做同样事情的方法,并为自己节省一个大量的重复.通常我不会建议这样做,但在这种情况下它是有道理的:

class AdminController 扩展 MY_Controller {{受保护的 $args;公共函数 __call($name,$args){$count = (!empty($args));$this->args = ($count)?$args:假;$this->load->view("admin/{$name}");}}

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

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

使用表单时,您可以将按钮设为自己的按钮,并将 id 作为隐藏字段.我只关注键 [0] 和子键 [0] 上的 customer 数组.当然,您可以对 customer[0] 数组进行循环以获取所有行:

<!-- tester.php 是您发送帖子要关注的页面.我不知道你的实际页面叫什么,你没有指出--><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"/><?phpforeach($arr['customer'][0][0] as $key => $value) {回声 $value;}?></表单>

当您单击 VIEW 按钮并发布到焦点页面时,您将获得该行的 id 值,您可以使用该 api 来提取该值(大概您知道如何获取API来做到这一点?).同样,您没有发布代码来显示您如何真正做任何事情,所以这只是一般性的.这是按钮将产生的结果.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天全站免登陆