I am using a Yii2 advanced app. The back end is fine, but I'm having a problem when I try to create a page (e.g., abc.php) in the front end/views folder, and then try to use a bootstrap ActiveForm class. For example:
<?php
use yii\helpers\Html;
use bootstrap\ActiveForm;
?>
<div class="client-vehicle-info-form">
<?php $form = ActiveForm::begin(['layout' => 'horizontal']); ?>
<?php ActiveForm::end(); ?>
</div>
Here is the error I am getting:
Fatal error: Class 'bootstrap\ActiveForm' not found in C:\xampp\htdocs\MyApp\frontend\views\abc.php on line 10
Related
First, i have the component file, located at resources/views/component.
game-card.blade.php
#props(['game'])
<div class = 'games'>
<a href = 'game/{{$game->id}}'> view page </a>
<p> game: {{$game->name}} </p> <br>
<p> genre: {{$game->genre}} </p> <br>
</div>
Then this component is called at my view, located in resources/views
listing.blade.php
#extends('layout')
#section('list')
<div class = 'listContainer'>
#unless(count($games) === 0)
#foreach($games as $game)
//doesn't work
<x-game-card :game = "$game"/>
#endforeach
#else
<p> 0 Games </p>
#endunless
</div>
#endsection
The variable $game is not passed in the component <x-game-card/>, i even tried to use short atribute syntax (<x-game-card :$game/>) but it still doesn't work.
If it matters, the file listing.blade.php is yielded at the file layout.blade.php, located in the same folder.
layout.blade.php
<body>
<!-- Header -->
#yield('list')
#yield('singlegame')
#include('partials._footer')
For any prop that you want to pass to your component, you need to register it on the component class. In this case, the class is probably app/View/Components/GameCard.php
On the class, you need to do something like:
class GameCard extends Component
{
public $game;
public function __construct($game)
{
$this->game = $game;
}
Source: https://laravel.com/docs/9.x/blade#passing-data-to-components
i found the root of the problem. I just can't believe that the solution is so simple. I am going to post it here so less people make the same mistake i did
First, create the class (i personally use the command php artisan make:component to do that) and update it just like Nico did.
Second, when you put the <x-component in the HTML, MAKE SURE TO NOT LEAVE ANY SPACES IN THE VARIABLE!!!
my mistake was using <x-game-card :game = "$game"/>
instead of <x-game-card :game="$game"/>
My URL is:
http://localhost/CodeIgniterCms/admin/dashboard/otherpages/123
where,
Codeigniter Cms
- admin
-- dashboard (the controller)
--- otherpages (Method)
Controller code
public function otherpages($somedata) {
$this->render('admin/second_view',$somedata);
}
Code in second_view.php
<pre>
<div class="container">
<?php echo $somedata;?>
</div>
</pre>
But it is throwing error
Unable to load the requested file: admin/123.php
Try this within your otherpages function:
$data['somedata'] = $somedata; <br/>
$this->load->view('admin/second_view',$data);
In my index.php view, I have a button, once clicked, a modal will pop up:
<p>
<?= Html::button(
'Create New BizAdmin',
['value' => Url::to(['createbizadmin']),
'class' => 'btn btn-success',
'id' => 'modalButton'
]) ?>
<?php
Modal::begin(['id' => 'modal']);
echo "<div id='modalContent'></div>";
Modal::end();
?>
</p>
My modal file is createbizadmin.php where it has the following codes:
<?php
use yii\helpers\Html;
/* #var $this yii\web\View */
/* #var $model app\models\User */
$this->title = 'Create New Bizadmin';
?>
<div class="user-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_formbizadmin', [
'model1' => $model1,
'model2' => $model2,
]) ?>
</div>
My problem is this:
As you can see, the navbar looks horrible. The menu list seems to overflow outside the modal.
How do I get rid of the navbar inside my modal? I can't seem to find which part of creatbizadmin.php I should edit.
Any thoughts?
I'm guessing that you have a controller somewhere that is handling the url createbizadmin. I'm also guessing that inside that controller action you are rendering the view file like this;
$this->render("createbizadmin");
If so, then that is your problem. By calling a view file directly, Yii will apply default layouts to the view file. You have no control over how this happens from within the called view file, and all your menus etc will be rendered.
To get around this you will probably need to render a partial file. This rendres the file without applying layouts. So use;
$this->renderPartial("createbizadmin")
Alternatively, if the modal content is being generated as a result of an ajax call, you can respond from the controller with;
$this->renderAjax("createbizadmin")
This article seems to have a good explanation of how best to achieve this; Render a form in a modal popup
<?php echo $users->links('view.name'); ?>
If I specify this view in laravel-4, what will be the code inside it? I can't find an example in the docs. Any example please?
according to this http://laravel.com/docs/pagination
If you use the paginator like this
<?php echo $users->links(); ?>
Laravel will use the default view which is defined inside app/config/view.php as
'pagination' => 'pagination::slider-3',
With this default option, your pagination will use the Illuminate/Pagination/views/slider-3.php view,
which is the following:
<?php if ($paginator->getLastPage() > 1): ?>
<ul class="pagination">
<?php echo $presenter->render(); ?>
</ul>
<?php endif; ?>
You can define your own view, and then use inside it the $paginator object to format it according to your needs.
You can see an example here.
I'm new to CodeIgniter and try to understand how to create forms. I searched both on the Net and stackopverflow but did not reach anything.
What i want is to create forms with helpers.
In order to do that in my controller create a function, named formElements() and the code is
public function formElements()
{
$this->load->helper(array('form'));
}
and in kayit.php
i try to create some html elements
<?=form_open('kayit/formElements')?>
<?=form_fieldset('Login Form')?>
<div class="textfield">
<?=form_label('username', 'user_name')?>
<?=form_input('user_name')?>
</div>
<div class="textfield">
<?=form_label('password', 'user_pass')?>
<?=form_password('user_pass')?>
</div>
<div class="buttons">
<?=form_submit('login', 'Login')?>
</div>
<?=form_fieldset_close()?>
<?=form_close();?>
However i take the error : Fatal error: Call to undefined function form_open() in C:\xampp\htdocs\pasaj\application\views\kayit.php on line 220
why?
You can also include the form helper in ./application/config/autoload.php file
$autoload['helper'] = array('form');
You can include the form helper in your Controller's constructor function, like:
$this->load->helper('form');
And it should work fine in view.
Ref: Form Helper
Hope it helps