如何在表中为Drupal 7 Editable字段创建仅供管理员使用

时间:2016-02-26 10:35:25

标签: php mysql arrays drupal drupal-7

 $header = array(
    array('data' => t('S No'), 'field' => 't.id'),
    array('data' => t('Country Name'), 'field' => 't.country_name'),
    array('data' => t('Status'), 'field' => 't.status'),
    array('data' => t('Added Date'), 'field' => 't.added_date'),
    array('data' => t('Action'), 'field' => 't.id',),
    array('data' => t('Action'), '',),
  );



$limit = 10; 
  $query = db_select('countries', 't')->extend('TableSort')->extend('PagerDefault')->limit($limit)->orderby('country_name', ASC);
  //condition();
  $query->fields('t');
  //$edit=echo '<i class="fa fa-pencil-square-o"></i>';
  //$edit=echo '<i class="fa fa-pencil-square-o"></i>';
  // Don't forget to tell the query object how to find the header information.
  $result = $query
      ->orderByHeader($header)
      ->execute(); 

  $rows = array();
   $i=1;

  foreach ($result as $row) {

    $rows[] = array(
    $i,
    //($x === 2) ? 0 : $x+1,
    //$row->id,
    $row->country_name,
    //$row->status,
    //$row->status,
    $status = ($row->status == 0) ? 'Inactive' : 'Active',
    date('d-m-Y H:i:s', strtotime($row->added_date)),
    l('Edit', 'mypages/countries/'. $row->id), 
    l('Delete', 'mypages/delete/'. $row->country_name)

    );
//print_r($status);
    $i++;
  }

在这个数据中,我从数据库中获取数据并显示它。现在我希望显示状态为动态,如管理员可以根据需要修改状态..

$status = ($row->status == 0) ? 'Inactive' : 'Active',

他可以在哪里active or inactive

如果我们可以提供有效或无效的下拉菜单,那么管理员可以选择状态...之后会自动更新为所选状态... 我正在显示S号码编号,这是在第一页中工作的数字,如编号自动增量,编号到第二页......编号系统从最初开始再次...

上述解决方案是什么

1 个答案:

答案 0 :(得分:0)

您可能需要创建另一个标题项来执行激活/停用操作,方法是检查user_access。 在行中,您可以添加指向是否激活/取消激活的链接,具体取决于当前状态。您可以通过传递查询参数,状态并更新状态,在单击激活或取消激活链接时重定向到编辑页面。