我正确使用api吗?

时间:2016-04-27 05:44:03

标签: php codeigniter api

enter image description here

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

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>

1 个答案:

答案 0 :(得分:0)

由于您没有与您实际工作相关的代码,因此以下是一些提示/想法:

在你的课程中,我建议使用__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作为隐藏字段。我将专注于密钥customer和子密钥[0]上的[0]数组。当然,您将在customer[0]数组上循环以获取所有行:

<!-- 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>

当您点击VIEW按钮并发布到焦点页面时,您将获得行的ID值,您可以使用api来拉取该值(可能您知道如何获取)这样做的API?)。再次,您没有发布任何代码来展示您是如何做任何事情的,所以这只是一般性的。这是按钮产生的内容。 id会根据您点击的行而改变。

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