2017-09-06 31 views
0

我試圖讓在笨添加和編輯一個視圖,當我嘗試更新HTML元素顯示,但是當我需要使用額外的元素隱藏我知道的問題是,我使用的foreach我能做些什麼來使工作蔭試圖讓在笨添加和編輯一個視圖,當我嘗試更新HTML元素顯示,但是當我需要使用添加元素隱藏

<?php include_once 'Header.php'; ?> 
    <div class="panel-body"> 
    <div class="row"> 
    <div class="col-lg-6"> 
<?php if($Operation == 2){ foreach ($records as $value) :?> 

    <?php if($Operation == 1) {echo form_open_multipart('Slider_Controller/AddNewSlid');} else if($Operation == 2){echo form_open_multipart('Slider_Controller/UpdateSlid/'.$value->Slid_ID. '');  } ?> 

    <div class="form-group"> 
     <label>Slider Title</label> 
?> 
     <input type="text" name='SlidTitle' class="form-control" value='<?php if($Operation == 2){echo $value->Title; } else { echo ""; }?>' placeholder="Slider Title"> 
    </div> 

<div class="form-group"> 
    <label>Upload Icone</label> 
    <input type="file" name='userfile'> 
</div> 

<div class="form-group"> 

    <label>Description</label> 
    <textarea class="form-control" rows="3" name='SlidDescription'><?php if($Operation == 2){echo $value->Description; }else if($Operation == 1){ echo null;}?></textarea> 

</div> 

<div class="form-group"> 

    <label>Select Slide status</label> 
    <select class="form-control" name='Staus'> 
     <option value='0'>Select status</option> 
     <option value='1' <?php if($Operation == 2){if ($value->Status == "1"){echo 'selected="selected"';}}?>>Active</option> 
     <option value='2' <?php if($Operation == 2){if ($value->Status == "2"){echo 'selected="selected"';}}?>>NonActive</option>   
    </select> 

</div> 

<?php endforeach; } ?> 

<input type="submit" name='fffff' value='go'>     
<button type="reset" class="btn btn-default">Reset Button</button> 
<?php echo form_close(); ?> 
<?php echo validation_errors('<span class="error">', '</span>'.'<br>'); ?> 

</div> 
<!-- /.col-lg-6 (nested) --> 

<!-- /.col-lg-6 (nested) --> 
</div> 
<!-- /.row (nested) --> 
</div> 
<!-- /.panel-body --> 
<?php include_once 'Footer.php'; ?> 
+0

只是一個小竅門,你不需要使用包括加載意見閱讀此https://www.codeigniter.com/user_guide/general/views.html#loading-multiple-views – user4419336

+0

請問您可以添加您的控制器代碼? –

回答

0

你的代碼只用於驗證$操作== 2,不存在如果塊$操作== 1

您已經書面形式AddNewSlid內如果$操作== 2,這是永遠不會是真實的。

相反,搬出AddNewSlid表單代碼出$操作== 2

0

嘗試這個

<?php include_once 'Header.php'; ?> 
<div class="panel-body"> 
    <div class="row"> 
    <div class="col-lg-6"> 
     <?php 
     //$Operation = 1; 
     $records = array('Slid_ID' => 2,"Title"=>"vijay", "Description" => 'bangalore india', 'Status' => 1); 
     $value = json_decode(json_encode($records));// comment this line means then it work for add else for edit 
//  echo "<pre>";print_r($value);die; 
     ?> 


     <form action="<?= 'Slider_Controller/AddNewSlid/' . (isset($value->Slid_ID) ? $value->Slid_ID : '') ?>"> 

     <div class="form-group"> 
      <label>Slider Title</label> 
      <input type="text" name='SlidTitle' class="form-control" value="<?= isset($value->Title) ? $value->Title : "" ?>" placeholder="Slider Title"> 
     </div> 

     <div class="form-group"> 
      <label>Upload Icone</label> 
      <input type="file" name='userfile'> 
     </div> 

     <div class="form-group"> 

      <label>Description</label> 
      <textarea class="form-control" rows="3" name='SlidDescription'><?= isset($value->Description) ? $value->Description : "" ?></textarea> 

     </div> 

     <div class="form-group"> 

      <label>Select Slide status</label> 
      <select class="form-control" name='Staus'> 
      <?php $status = isset($value->Status) ? $value->Status : '' ?> 
      <option value=''>Select status</option> 
      <option value='1' <?= ($status == "1") ? 'selected' : '' ?>>Active</option> 
      <option value='2' <?= ($status == "2") ? 'selected' : '' ?>>NonActive</option>   
      </select> 

     </div> 

     <input type="submit" name='fffff' value='go'>     
     <button type="reset" class="btn btn-default">Reset Button</button> 
     </form> 
     <?php echo validation_errors('<span class="error">', '</span>' . '<br>'); ?> 

    </div> 
    <!-- /.col-lg-6 (nested) --> 

    <!-- /.col-lg-6 (nested) --> 
    </div> 
    <!-- /.row (nested) --> 
</div> 
<!-- /.panel-body --> 
<?php include_once 'Footer.php'; ?> 

這個頁面是添加/編輯

  • 請繞道$value只編輯其他明智$value應該是空的

`

相關問題