doushan5245 2012-07-03 06:44
浏览 46
已采纳

codeigniter视图未在带参数的构造函数中加载

I am trying to load a view from constructor with parameter $data. Earlier it was working fine and now suddenly it stopped working. Below is the code:

permissionerror View

    <table width="100%" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="6" align="left" valign="top" background="<?php echo base_url();?>images/bg/topbg.gif"><img src="<?php echo base_url();?>images/bg/top-left.gif" width="5" height="34" /></td>
                <td height="34" align="left" valign="middle" background="<?php echo base_url();?>images/bg/topbg.gif" class="heading">Access Forbidden</td>
                <td width="6" align="right" valign="top" background="<?php echo base_url();?>images/bg/topbg.gif"><img src="<?php echo base_url();?>images/bg/top-right.gif" width="5" height="34" /></td>
              </tr>
              <tr>
                <td align="left" valign="top" background="<?php echo base_url();?>images/bg/main-content-bg-left.gif">&nbsp;</td>
                <td height="165" valign="top"  bgcolor="#FFFFFF" class="leftredheading"><div style="margin:30px auto;padding-left:15px"><? if(isset($sn_error)) echo $sn_error;?></div></td>
                <td align="right" valign="top" background="<?php echo base_url();?>images/bg/main-content-bg-right.gif">&nbsp;</td>
              </tr>
              <tr>
                <td align="left" valign="bottom" background="<?php echo base_url();?>images/bg/bottom-bg.gif"><img src="<?php echo base_url();?>images/bg/bottom-left-corner.gif" width="5" height="5" /></td>
                <td valign="top" background="<?php echo base_url();?>images/bg/bottom-bg.gif"></td>
                <td align="right" valign="bottom" background="<?php echo base_url();?>images/bg/bottom-bg.gif"><img src="<?php echo base_url();?>images/bg/bottom-right-corner.gif" width="5" height="5" /></td>
              </tr>
            </table>

Template code:

<?php $this->load->view('includes/login/header'); ?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#e7e7de">
  <tr>
    <td width="18"><img src="<?php echo base_url();?>images/bg/zero.gif" width="18" height="1" /></td>
    <td width="191"><img src="<?php echo base_url();?>images/bg/zero.gif" width="191" height="1" /></td>
    <td width="18"><img src="<?php echo base_url();?>images/bg/zero.gif" width="18" height="1" /></td>
    <td width="100%">&nbsp;</td>
    <td width="161"><img src="<?php echo base_url();?>images/bg/zero.gif" width="18" height="1" /></td>
    <td width="191"><img src="<?php echo base_url();?>images/bg/zero.gif" width="191" height="1" /></td>
    <td width="18"><img src="<?php echo base_url();?>images/bg/zero.gif" width="18" height="1" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="left" valign="top"><table width="191" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td background="<?php echo base_url();?>images/bg/left-menu-white-bg.gif"> <?php $this->load->view('includes/login/top_right'); ?> </td>
      </tr>
      <tr>
        <td height="50" background="<?php echo base_url();?>images/bg/left-menu-white-bg.gif">&nbsp;</td>
      </tr>
      <tr>
        <td background="<?php echo base_url();?>images/bg/left-menu-white-bg.gif"><table width="166" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td align="left" valign="top"><img src="<?php echo base_url();?>images/bg/needhelp-top.gif" width="166" height="7" /></td>
          </tr>
          <tr>
            <td align="center" valign="top" bgcolor="#F8F7EC"> <?php $this->load->view('includes/login/bottom_right'); ?>
                <br /></td>
          </tr>
          <tr>
            <td align="left" valign="top" bgcolor="#F8F7EC"><img src="<?php echo base_url();?>images/bg/needhelp-bottom.gif" width="166" height="7" /></td>
          </tr>
        </table>
          <br /></td>
      </tr>
      <tr>
        <td background="<?php echo base_url();?>images/bg/left-menu-white-bg.gif"><table width="191" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="6" align="left" valign="top"><img src="<?php echo base_url();?>images/bg/left-bttom.gif" width="6" height="6" /></td>
            <td width="100%" background="<?php echo base_url();?>images/bg/leftbottom.gif"></td>
            <td height="6" align="right" valign="top"><img src="<?php echo base_url();?>images/bg/right-bttom.gif" width="6" height="6" /></td>
          </tr>
        </table></td>
      </tr>
    </table>
         <br /></td><td>&nbsp;</td>
    <td valign="top"  <? if($main_content != 'dashboard' || $main_content == 'publisher_dashboard') { ?> colspan="3" <? } ?>><?php $this->load->view($main_content); ?></td>
    <td>&nbsp;</td>
    <? if($main_content == 'dashboard' || $main_content == 'publisher_dashboard') { ?>
    <td align="right" valign="top"> <?php $this->load->view('includes/login/left'); ?>
    </td>
    <? } ?>
    <td>&nbsp;</td>
  </tr>
</table>
<?php $this->load->view('includes/login/footer'); ?>

Here in the above code i am checking whether logged in user is having permission for access then do else part otherwise through the error from if case block.

In IF case it loads the error template.

Please somebody help me to fix the above issue ASAP!

  • 写回答

1条回答 默认 最新

  • dongqiao8421 2012-07-03 07:23
    关注

    Call parent::__construct(), not parent::Controller().

    Edit:

    After it was made clear that CodeIgniter 1.7.1 is used and after the view itself was shown, this is your issue:

    Your view tries to echo $error instead of $sn_error. If you don't pass $data to the view, then $sn_error (which is checked for) isn't set and that error doesn't occur - that's why the view gets loaded in that case.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python验证码滑块图像识别
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)