Codeigniter get_instance() in a view - codeigniter

In my app, i use get_instance() in my view, below is my complete code
<h3 class="title">
<?php echo get_instance()->router->fetch_method();?>
</h3>
what it is dangerous?

Related

How to change which template is extended based on user authentication

I am using Laravel 6.20.11, and I have published the Laravel blade error templates. What I need to have happen is that if the user is authenticated, the error message extends the internal-only layout, and if not, it extends the public layout like so:
#auth
#extends ('int-layouts.partials.wrapper')
#section ('error')
<div class="be-content">
<div class="main-content container-fluid">
<div class="container py-5">
<div class="row">
<div class="col-lg-8">
<div class="text-block">
<h1>404 - Not Found</h1>
<p class="text-muted text-uppercase mb-4">Sorry, we couldn't find the page you were looking for.
Please contact the administrator<br/>
Or go back to the <a class="navbar-brand py-1" href="/controlpanel/">Dashboard</a></p>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
#endauth
#guest
#extends ('ext-layouts.master')
#section('error')
<div class="container py-5">
<div class="row">
<div class="col-lg-8">
<div class="text-block">
<h1>404</h1>
<p class="text-muted text-uppercase mb-4">Sorry,You are trying to reach the page that does not exist.<br>
Please contact the administrator <br/> Or go back to the <a class="navbar-brand py-1" href="/">Home Page</a></p>
</div>
</div>
</div>
</div>
#endsection
#endguest
The problem I am having is that when I test the 404 error using abort(404) or by trying to access a route that doesn't exist, the error message displays twice and the page inherits the int-layouts.partials.wrapper even when the user isn't authenticated.
Is this expected behavior or am I doing something wrong in my blade file?
You can try to use a conditional in one #extends directive:
#extends (auth()->check() ? 'int-layouts.partials.wrapper' : 'ext-layouts.master')
Then you can use a conditional after this inside your section.
#section('error')
#auth
#else
#endif
#endsection
The #extends directive is not actually returning output directly into the compiled result like most directives do. The compiled PHP for this is held in an array to be added later.
Everything inside the ( ) of the directive is being used as a literal to call make on the View Factory:
"<?php echo \$__env->make({$expression}, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>"
If you found the compiled view for this Blade template you would see this:
<?php echo \$__env->make(auth()->check ? 'int-layouts.partials.wrapper' : 'ext-layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
The first argument to make ends up being your view name when this compiled view is executed.
In Controller function:
$layouts = Auth::user->admin ? 'view.admin' : 'view.student'; //
view.admin or view.student is the blade file which you want to render
dynamically.
return view('welcome',compact('layouts'));
Write in Blade File:
#extends($layouts)
#section('...')
...
#endsection

Including an php which is including another php

I am new to php language but I need the include() function to separate my site into different PHPs in order to call it again on different pages.All worked fine until I came to include a PHP which includes another PHP . Here's the code in html file :
<?php
set_include_path('contents');
include 'index_page.php';
?>
index_page.php which includes sidebar.php :
<?php
echo
'<div class="body2">
<div class="content">
<h1>text</h1>
<img src="images/homeimage.jpg">
<p>some text</div> '. include "sidebar.php"; '</div>';
?>
sidebar.php:
<?php
echo
'<div id="sidebar">
<ul>
<li><div class="arrow-up"></div>اشترك معنا</li>
<li>text</li>
<li>text</li>
<li>text</li>
<li>text</li>
<li>text</li>
</ul>
</div>';
?>
The result that appears in the browser was that the sidebar.php was included before the text as if the code was like that :
<?php
echo
include "sidebar.php";.'<div class="body2">
<div class="content">
<h1>text</h1>
<img src="images/homeimage.jpg">
<p>some text</div> </div>';
?>
Any solutions ??

Calling a view inside a view

Is it possible to call a view inside a view in Laravel?
<div id="main_content">
<?php View::make('content_view'); ?>
</div>
like it nicely worked in Codeigniter
<div id="main_content">
<?php $this->load->view('content_view'); ?>
</div>
You dont 'call' a view, you 'include' the view - see template docs for more examples at Laravel.com
<div id="main_content">
#include('content_view')
</div>

Navigating and updating content in a CodeIgniter application

I am using CI with Twitter Bootstrap for a basic site:
In my main layout view this is how the main content area is setup:
<div class="container-fluid">
<div class="row-fluid">
<div class="span1"></div>
<div class="span8">
<?php echo $this->load->view($subview); ?>
</div>
<div class="span3" id="sidebar">
<?php echo $this->load->view($this->global_data['sidebarview']); ?>
</div>
</div>
</div>
One sidebar view is this:
<div class="container-fluid" id="sidebar-about">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-info-sign"></i> More about us</li>
<li class="active">Who are we?</li>
<li>Why we did it?</li>
<li>What we promise?</li>
<li class="nav-header"><i class="icon-asterisk"></i> Services</li>
<li>Free</li>
<li>Premium</li>
</ul>
</div><!--/.well -->
</div><!--/span-->
Every link in this sidebar i want to update the div with class="span8" from my main layout.
How should i do that? Should i use ajax calls to update the content of the span8 div? or just create more methods in about controller?

How to display system message outside of template in Joomla 1.5?

Joomla Geeks!
Please help me. Web designers created design for Joomla, where
<jdoc:include type="message" />
should be located inside of custom component's view (default.php). It's because of divs nesting, I can't change anything.
Nevertheless, I have to find a solution to include Joomla system messages in component's view (default.php) instead of template's index.php, how to do that? Is it possible?
UPD: I've solved the problem, but now I need to override this code:
<dl id="system-message">
<dt class="message">MESSAGE_TYPE</dt>
<dd class="message message fade">
<ul>
<li>MESSAGE_TEXT</li>
</ul>
</dd>
</dl>
with this one:
<div class="message">
<span class="jsMessage info_message">
<span>
MESSAGE_TEXT <a class="close jsCloseMessage" href="javascript:void(0)"></a
</span>
</span>
</div>
Should I use templates/mytemplate/html/modules.php file for that?
$document = & JFactory::getDocument();
$renderer = $document->loadRenderer('message');
$msg=$renderer->render();

Resources