How to implement this kind of layout in new model? - php

In
#dektrium/user/views/admin/_account.php
#dektrium/user/views/admin/_info.php
#dektrium/user/views/admin/_profile.php
there are
<?php $this->beginContent('#dektrium/user/views/admin/update.php', ['user' => $user]) ?>
'the rest codes'
<?php $this->endContent() ?>
and in #dektrium/user/views/admin/update.php there're
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-body">
<?= $content ?>
</div>
</div>
</div>
the $content will be replaced by code between 'beginContent' and 'endContent', how to implement this kind of layout in my new backend model 'Rayon'? I tried write a similar CRUD code, but keep getting an error 'Undefined variable content'.
Thank you for your help.

the row with code
<?php $this->beginContent('#dektrium/user/views/admin/update.php', ['user' => $user]) ?>
tells to the "view" which is, to take the code from the reference and add it to the place where the call is invoked ..
It performs an equivalent action to "include" within more the possibility of pass the variables to use in the "content"
then you should create the part of view that you want to reuse .. and the views in which you want to call to add this type of call
You can do something similar directly reusing the render () function inside de view and indicating which (other) view and which variables to use.
for (simple) example
view container_view.php in yourapp/views
<div>my container test</div>
<?= $content ?>
then
You want that the code in container_view is placed in a way that the code inside beginContent and endContent of the
create.php in yourapp/views/ is place in the same place you have $content in the container
<?php $this->beginContent('yourapp/views/container_view.php', ['model' => $model]) ?>
<div>this code is placed in $container</div>
<div>and the value of the var model is passed</div>
<br />
<?= $model->name '>
<?php $this->endContent() ?>

Related

Setting a value for global variable in view that can be used in Controller Laravel 5.5

I am a beginner of Laravel. I reading the discussions on implementing global variables. But in my case, I want to set the value of the global variable from the view that can be used in the controller.
My sample code in button from adminHome.blade.php
<!--CAMPUS BUTTON-->
#foreach($campuses as $campus)
<div class="col-md-4">
<div class="card card-user box">
<div class="image" style="background-color:#00D27F;"></div>
<div class="content bg">
<div class="author">
<br><br><br><br><br><br>
<img class="" src="{{ asset('images/icon-school.png') }}" alt="..."/><br><br><br>
<h4 class="title"><b>{{$campus->campus_name}} Campus</b></h4>
{{--SOMEWHERE HERE I'LL SET THE VALUE OF THE GLOBAL VARIABLE. THE VALUE I SHOULD SET IS {{$campus->id}}--}}
<h5>{{$campus->name}} Campus</h5>
<hr>
<h5 class="title text-center">
</h5>
<a href="{{ route('dashboard') }}">
<p>VIEW</p>
</a>
</div>
</div>
</div>
</div>
#endforeach
As my code shown above, when I click that button, it would also set the value of the global variable so that in order to proceed on the next page, all the data related on that campus will only be shown. How can I do this? Thanks
May I got your Point#
there have no way to access variable from view to controller.
you can put variable in session. so that you can use from anywhere.
session(['your_key' => 'your_value']);
I think what you're looking for is when the user presses VIEW it opens the campus details yes?
In that case you can do:
{{ route('dashboard',['campus_id' => $campus->id]) }}
You are using a named route dashboard and you can pass in vars to that route with the above code.
Source: Laravel Named Routes Docs
You could either create and submit a form that will store the value in the back-end, in a database for example and later send the variable to the next view return view( 'next_page', ['variable' => $campus_id] );.
Or, you could just get the value from the form with some JS or jQuery magic and use GET variables to send it to the next page. http://example.com/next-page?variable=campus_id and echo it with {{ $_GET['variable'] }}

Smarty assign value to variable inside included template

I have a listing item template as below:
<div class="listing-item">
<div class="photo">{$thumbnail}</div>
<div class="title">{$name}</div>
<div class="price">{$price} {$currency}</div>
<div class="location">{$city}/{$town}</div>
</div>
I'm including this template from another template file, and assign it into a variable named listing_item, as shown below:
<div class="listing-box-container clearfix">
{include file="common/product/listing_item.tpl" assign=listing_item}
</div>
Now i have var a variable named listing_item that holds template for single listing item.
I want to assign value to variable inside listing_item like:
{assign var="$listing_item.thumbnail" value="Sometown"}
I'm not passign values while i'm including the template because i want to use listing_item multiple times so i dont want to load it everytime i need it.
The idea here is include the template once, and assign values & echo where it needed.
So, how can i assign value to variable inside a template which has already been included and assigned to a variable?
Or, what is the best practice to archieve my needs in smarty?
Any help will be highly appreciated
If You are using smarty3 You can use this constuct:
{$listing_item = [
'thumbnail' => 'some_thumbnail',
'title' => 'some_title',
'price' => 'some_price'
]}
More about variables syntax here http://www.smarty.net/docs/en/language.syntax.variables.tpl
Now pass it to the template:
<div class="listing-box-container clearfix">
{include file="common/product/listing_item.tpl" listing_item=$listing_item}
</div>
And within the template use:
<div class="listing-item">
<div class="photo">{$listing_item.thumbnail}</div>
<div class="title">{$listing_item.name}</div>
<div class="price">{$listing_item.price} {$listing_item.currency}</div>
<div class="location">{$listing_item.city}/{$listing_item.town}</div>
</div>

How can I do a simple search form/function in yii2?

I want to do a search using a form which will search name field, brand field and category field.
Should I be using post or get for this situation?
How/where should I be creating my query search model, model or controller?
Any code snippets would be great.
I have the following in my view:
<?php $form = ActiveForm::begin(['id' => 'home-search','method' => 'get', 'action' => Url::to(['productitem/search'])]); ?>
<?= $form->field($productitem, 'name')->textInput(array('placeholder' => 'What are you looking for?'))->label(false) ?>
<?= $form->field($productitem, 'brand_id')->dropDownList(
ArrayHelper::map(ProductBrand::find()->all(),'id','name'),
['prompt'=>'Select Brand']
)->label(false) ?>
<?= $form->field($productitem, 'category_id')->dropDownList(
ArrayHelper::map(ProductCategory::find()->all(),'id','name'),
['prompt'=>'Select Department']
)->label(false) ?>
<div class="form-group search-button">
<button type="submit" class="btn btn-primary" name="login-button">Search <i class="fa fa-lg fa-arrow-circle-o-right"></i></button>
</div>
<?php ActiveForm::end(); ?>
The answer to your questions:
I would use get just for the convenience of pressing the "back" button. You are not changing the database at all so a GET should provide enough security / convenience
search model should be in the [Model]Search. Yii2 has specialized search models on top of the normal models why not keep them there? That is exactly what they are there for.
No code snippets SO helps you with your code, does not usually writes it for you. But then again somebody will probably come and spoon feed you code anyway so you will not learn anything so enjoy.

Laravel not loading view. Error in a storage\framework\view file

I'm unable to access my orders_index view from my OrdersController.
orders_index.blade.php
location: \resources\views\orders
#extends 'app'
#section('heading')
Orders Index
#endsection
#section('content')
<section>
content section
</section>
#endsection
OrdersController
location: app\Http\Controllers
public function index(){
return view('orders.orders_index');
}
routes.php
Route::get('orders', 'OrdersController#index');
file in which error is indicated: f2e7d6f3f58a0e30e17a0c631c812b28
'/app'
<?php $__env->startSection('heading'); ?>
Orders Index
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
<section>
content section
</section>
<?php $__env->stopSection(); ?>
<?php echo $__env->make(, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
I think it has something to do with namespacing, which I have not quite figured out yet. I haven't seen any information online yet about namespacing in the view, so I do not know if I am to use namespace in the views.
It should be #extends('app') not #extends 'app'. For Laravel what you did now was like writing: #extends() 'app' So it tries to call the function make with an empty first parameter (because you didn't pass anything to #extends) and hence you get that syntax error.

How to change the default setFlash () in CakePHP?

How to change the default setFlash () in CakePHP ?
How or where change this default element:
<div id="flashMessage" class="message">
My message.
</div>
Necessary:
<div id="myid" class="myclass">
My message.
</div>
Thanks.
According to the documentation:
Create the file app/View/Elements/flash_custom.ctp and build our custom flash element:
<div id="myid"><?php echo $message; ?></div>
Then call setFlash() with those parameters:
<?php
$this->Session->setFlash('My message.', 'default', array('class' => 'myclass'));
The output in your template from using $this->Session->flash() with the above example would be then:
<div id="myid" class="myclass">My message.</div>

Categories