问题
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>
回答1:
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
)
来源:https://stackoverflow.com/questions/36881224/am-i-using-api-correctly