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
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"/>
I am trying to set flash data in Controller 1 and redirect to Controller 2, where I store the data in a $page_data variable to get it displayed in View 2. The following are my codes:
Controller 1:
$this->session->set_flashdata('message','my custom message');
redirect('controller2','refresh');
Controller 2:
$page_data['loginmessage'] = $this->session->flashdata('message');
$this->load->view('view2',$page_data);
View 2:
<p> <?php echo $loginmessage ?> </p>
CodeIgniter is able to load View 2, but does not display the login message. To put in another way, I am not getting the flash data message in Controller 2.
No need to use controller 2 for showing flashdata. Use this
Controller1
$this->session->set_flashdata('message','my custom message');
redirect('controller2/any_method');
Now you may use message in view2.php (which you are loading through controller 2) file as
<p> <?php echo $this->session->flashdata('message'); ?> </p>
You need to change the small piece of code your code to redirect it correctly.
Controller 1:
function first()
{
$this->session->set_flashdata('message','my custom message');
redirect("/controller2/second", "refresh");
}
Controller 2:
function second()
{
$page_data['loginmessage'] = $this->session->flashdata('message');
$this->load->view('view2',$page_data);
}
Also, if you refresh the page then flash data will disappear because it will appear only once.
View code is same
<p> <?php echo $loginmessage ?> </p>
I have a page system in Laravel - where I pass data from controller to view.
$this->data['title'] = $row->title;
$this->data['breadcrumb'] = $row->bc;
Now I passed it as follows:
return View::make('Themes.Page', $this->data);
In the view file, I access the data as follows:
{{$breadcrumb}}
What I am trying to do now is to pass this data in nested views:
$this->layout->nest('content',$page, $this->data);
(Content is the {{content}} in the view which will be replaced with $page contents. I want to pass the $this->data just as before but now I get an error:
Variable breadcrumb not defined.
Note: Laravel Version 4.2 $this->layout is set in constructor to a
template file (Themes.Page)
Actually you don't need to pass any separate data to your partial page(breadcrumb)
controller page
$this->data['title'] = $row->title;
$this->data['breadcrumb'] = $row->bc;
return View::make('idea.show',array("data"=>$this->data));
main view page
<div>
<h1>here you can print data passed from controller {{$data['title']}}</h1>
#include('partials.breadcrumb')
</div>
your partial file
<div>
<h1>here also you can print data passed from controller {{$data['title']}}</h1>
<ul>
<li>....<li>
<li>....<li>
</ul>
</div>
for more information on this you can check following links http://laravel-recipes.com/recipes/90/including-a-blade-template-within-another-template or watch this video https://laracasts.com/series/laravel-5-fundamentals/episodes/13
You should pass data as follows
return View::make('Themes.Page')->with(array(
'data'=>$this->data));
or (since you're passing only 1 variable)
return View::make('Themes.Page')->with('data', $this->data);
and further you can pass it on to nested views as by referencing $data
$dataForNestedView = ['breadcrumb' => $row->bc];
return View::make('Themes.Page', $this->data)->nest('content', 'page.content', $dataForNestedView);
In the Themes.Page view render nested view:
<div>
{{ $content }} <!-- There will be nested view -->
</div>
And in the nested page.content view you can call:
<div>
{{ $breadcrumb }}
</div>
*div tag is only for better understanding.
Okay, after intense search, I figured out that there was a bug in the Laravel version 4.2 I was using.
Laravel 5 works.
For laravel 4.2, a better option would be to pass array of data objects using View::share('data',$objectarray) while passing the data from controller.
Thanks everyone for help
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);
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