php variable that stores html code

Asked

Viewed 79 times

1

I haven’t used php for 2-3 years, I even learned about it, but recently I went to look at some code to make some modifications to a site and I’m having a great difficulty, the first is this, has a php page that makes the creation of a menu in html and dps of this menu has a php code with a variable, and it simply makes implements all the rest of the content of the site, if I delete it is only the menu on the site. I wanted to know what the name of this, how to do it, and if possible some site/video for me to study on. Obgd!

<header>
  <nav class="navbar navbar-expand-lg fixed-top navbar-dark bg-dark" style="border-bottom: 2px solid #fff;">
    <div class="container">

      <a class="navbar-brand display-25" href="<?php echo base_url(); ?>"><?php echo $this->settings->site_name; ?></a>

  <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarTogglerDemo03">

    <div class="dropdown">
        <button class="drop-menu btn dropdown-toggle"
          type="button" id="dropdownMenu1" data-toggle="dropdown"
          aria-haspopup="true" aria-expanded="false">
            <span class="f-size-18"><i class="fas fa-gamepad"></i> Menu2</span>
        </button>
        <div class="dropdown-menu" aria-labelledby="dropdownMenu1">
          <a class="dropdown-item" href="<?php echo base_url('/login'); ?>">SubMenu1</a>
          <a class="dropdown-item" href="<?php echo base_url('/login'); ?>">SubMenu2</a>
          <a class="dropdown-item" href="<?php echo base_url('/login'); ?>">SubMenu3</a>
       </div>
    </div>

    <div class="dropdown">
        <button class="drop-menu btn dropdown-toggle"
          type="button" id="dropdownMenu1" data-toggle="dropdown"
          aria-haspopup="true" aria-expanded="false">
            <span class="f-size-18"><i class="fab fa-bitcoin"></i> Menu1</span>
        </button>
        <div class="dropdown-menu" aria-labelledby="dropdownMenu1">
          <a class="dropdown-item" href="<?php echo base_url('/login'); ?>">SubMenu1</a>
          <a class="dropdown-item" href="<?php echo base_url('/login'); ?>">SubMenu2</a>
       </div>
    </div>

    <ul class="navbar-nav ml-auto my-2 my-lg-0 f-size-18">
      <li class="nav-item">
        <a class="nav-link" href="<?php echo base_url(); ?>">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="<?php echo base_url('/login'); ?>">Login</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="<?php echo base_url('/user/register'); ?>">Register</a>
      </li>
    </ul>

  </div>
  </div>
</nav>
</header>
<!-- <?php if ($this->session->flashdata('message')) : ?> <div class="alert alert-success alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button> <?php echo $this->session->flashdata('message'); ?> </div> <?php elseif ($this->session->flashdata('error')) : ?> <div class="alert alert-danger alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button> <?php echo $this->session->flashdata('error'); ?> </div> <?php elseif (validation_errors()) : ?> <div class="alert alert-danger alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button> <?php echo validation_errors(); ?> </div> <?php elseif ($this->error) : ?> <div class="alert alert-danger alert-dismissable"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button> <?php echo $this->error; ?> </div> <?php endif; ?> --> <?php // Main content ?> <?php echo $content; ?> <code>

The PHP variable I refer to is at the end of this code ("$content;").

  • Hello! First, you have to put in the code so we can help you. At first, the code of the page "which creates a menu in html and then dps of this menu has a php code with a variable". Edit your question and add its code so we can see. Greetings.

  • Okay, I’ll put, vlw!

  • Well. Likely to be using a framework. Yii Framework or other. A framework that uses MVC (Model-view-controller). This <?php echo $content; ?> is in the View and the data is worked and manipulated together with the Model and the Controller. See here, a case where the information comes from C (Controller) and then the data captured in V (View): https://www.codeigniter.com/user_guide/general/views.html See : $data['title'] = "My Real Title"; is in the Controller and then in the View you call <title><?php echo $title;?></title>

  • This site uses that same framework, codeigniter, but can’t understand it. How do I know which Controller q is this my variable? There is no reference. The page code is basically the one shown above

  • Search the Controller folder application/controllers/, can be another way. See the name of your preview file and find the control based on the view name.

  • I managed to find the Controller, Thanks! .. Now is to study further to understand all this kkk

  • I was going to add an answer about the MVC buffer with the basics within your question explaining how to print a content in View, using MVC. But the issue was closed. Penalty

  • It would be a good one for those who have the same problem ... A feather msm

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.