编程语言
首页 > 编程语言> > php-如何使表中的Drupal 7 Editable字段仅供管理员使用

php-如何使表中的Drupal 7 Editable字段仅供管理员使用

作者:互联网

 $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++;
  }

在此数据中,我正在从数据库中获取数据并显示它..现在,我想将状态显示为动态,例如admin可以根据需要修改状态.

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

他可以使活跃或不活跃的地方

如果我们可以在下拉菜单中更好地选择启用或禁用,那么管理员可以选择状态.此后,系统会自动更新为所选状态…
并且我正在显示S no作为编号,即编号在第一页工作,如编号自动递增,其中编号到第二页..编号系统又从头开始…

以上是什么解决方案

解决方法:

您可能必须通过检查user_access来创建另一个标头项以执行激活/停用操作.
在行中,您可以添加链接,以指示是否根据当前状态激活/停用.您可以通过传递查询参数,状态和更新状态,单击激活或停用链接来重定向到编辑页面.

标签:php,arrays,mysql,drupal,drupal-7
来源: https://codeday.me/bug/20191012/1903071.html