我正确使用api吗? [英] Am I using api correctly?

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

问题描述



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



AdminController.php



 <?php 
class AdminController extends MY_Controller {
function __construct()
{
parent: :__构造();
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 catalog()
{
$ 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>这是一个简单的英雄单位,一个简单的jumbotron式组件,用于引起对特色内容或信息的额外关注。< / p>
< p>< a class =btn btn-primary btn-lg>了解详情< / a>< / p&
< / div>
< / div>


解决方案

因为你没有与你实际上下面是一些提示/想法:



在你的类上,而不是做一堆方法,所有的做同样的事情,我建议使用 __ call()重载类,并节省了大量的重复。通常我不会建议这个,但在这种情况下是有道理的:

  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});
}
}

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

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

使用表单时,您可以使用 id 作为隐藏字段。我只是关注 [0] 上的客户数组和子键 0] 。您当然会在 customer [0] 数组上执行一个循环,以获取所有行:

 <! -  tester.php是您发送帖子以专注于的页面。 
我不知道你的实际页面是什么,你没有指示
- >
< form action =/ tester.phpmethod =post>
< input type =textname =idvalue =<?php echo $ arr ['customer'] [0] [0] ['id'];?& />
< input type =submitname =viewvalue =VIEW/>
< input type =submitname =deletevalue =DELETE/>
< input type =submitname =editvalue =EDIT/>
<?php
foreach($ arr ['customer'] [0] [0] as $ key => $ value){
echo $ value;
}
?>
< / form>

当您单击 VIEW 按钮到焦点页面,你留下的行的id值,你可以使用你的api拉这只是一个(可能你知道如何获得API这样做吗?)。再次,你没有代码发布,以显示你做什么真的,所以这只是一般。这里是按钮将产生。 id 会根据您点击的行而改变。

  

[id] => 1
[view] => VIEW

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天全站免登陆