Returning full text search results - php

I am following this tutorial :
http://creative-punch.net/2013/12/implementing-laravel-4-full-text-search
I have followed it through adapting to my own project my question is how do I display the results that I have queried thanks
code as follows : view
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel PHP Framework</title>
<style>
#import url(//fonts.googleapis.com/css?family=Lato:700);
body {
margin:0;
font-family:'Lato', sans-serif;
text-align:center;
color: #999;
}
.welcome {
width: 300px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -100px;
}
a, a:visited {
text-decoration:none;
}
h1 {
font-size: 32px;
margin: 16px 0 0 0;
}
</style>
</head>
<body>
<div class="search">
{{ Form::model(null, array('route' => array('ec2_instance.search'))) }}
{{ Form::text('query', null, array( 'placeholder' => 'Search query...' )) }}
{{ Form::submit('Search') }}
{{ Form::close() }}
</div>
</body>
</html>
my controller :
<?php
class PostsController extends BaseController {
public function postSearch(){
$q = Input::get('query');
$posts = ec2_instance::whereRaw("MATCH(instance_id,instance_type,availability_zone, status_checks,alarm_status, public_dns, key_name ) AGAINST(? IN BOOLEAN MODE)",
array($q))->get();
return View::make('ec2_instance.search', compact('ec2_instance'));
}
}
?>
my routes :
Route::get('/', function()
{
return View::make('search');
});
Route::post(
'ec2_instance/search',
array(
' as' => 'ec2_instance.search',
'uses' => 'PostsController#postSearch'
)
);
?>

Ok I'll make some assumptions here so you may have to alter the code a bit to fit your needs...
First you certainly don't need to pass ec2_instance to the view but rather the result $posts
return View::make('ec2_instance.search', compact('posts'));
Now since your result will be a collection of posts you need to loop over it in your view:
ec2_instance.search
#foreach($posts as $post)
{{-- display properties here --}}
{{ $post->key_name }}
{{-- etc... --}}
#endforeach

Related

why blades directives still visible?

I'm discovering Laravel and VueJs
I just intalled it using laravel installer
I think blade is not working because when i do npm run dev, the welcome.blade.php looks like that:
As you can see, the blade directives appear...
I didn't change the code give but it looks like this:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Nunito', sans-serif;
font-weight: 200;
height: 100vh;
margin: 0;
}
.full-height {
height: 100vh;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}
.position-ref {
position: relative;
}
.top-right {
position: absolute;
right: 10px;
top: 18px;
}
.content {
text-align: center;
}
.title {
font-size: 84px;
}
.links > a {
color: #636b6f;
padding: 0 25px;
font-size: 13px;
font-weight: 600;
letter-spacing: .1rem;
text-decoration: none;
text-transform: uppercase;
}
.m-b-md {
margin-bottom: 30px;
}
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
#if (Route::has('login'))
<div class="top-right links">
#auth
Home
#else
Login
#if (Route::has('register'))
Register
#endif
#endauth
</div>
#endif
<div class="content">
<div class="title m-b-md">
Laravel
</div>
<div class="links">
Docs
Laracasts
News
Blog
Nova
Forge
Vapor
GitHub
</div>
</div>
</div>
</body>
</html>
If someone have an idea to fix that ;)

OctoberCMS DynamicPDF dynamic Header Content Text

I am using OctoberCMS DynamicPDF Plugin which is working absolutely fine as per my requirement.
Howerver, I have dynamic PDF header text content and I am trying to Overwrite my Header Content but its not working. Here is what I have tried so far.
Template file
{% set headerTExt = 'asdf' %}
Layout file
<html>
<head>
<style type="text/css" media="screen">
{{ css|raw }}
</style>
<title>Regency Brochure</title>
</head>
<div id="header">
<div style="display: inline-block; position: absolute; left: 2.5%; top: 12px;">
<img src="{{ logo }}" style="width: 60px; height:auto; margin-top:5px;"/>
</div>
<div style="text-align: right; font-size: 20px; color: #b49132; text-transform: uppercase; font-family: 'Montserrat-Bold'; position: absolute; right: 3.5%; top: 25px;">
{{ headerTExt }}
</div>
</div>
<div id="footer">
<div class="footerText">www.regencycorporate.com.au</div>
</div>
{{ content_html|raw }}
</html>
Layout File CSS
#page { margin:25mm 0px 8mm 0px;}
header { position: fixed; left: 0px; top:-25mm; right: 0px; height: 22mm; background-color: #fff; border-bottom: solid 1px #d8d8d8;}
footer { position: fixed; left: 0px; bottom:-8mm; right: 0px; background-color: #b49132; height: 11mm; }
footer .footerText { font-size: 14px; text-align: center; color: white; font-family: 'Montserrat-Medium'; font-weight:400; padding-top:8px; }
content{
height:645px;
padding:0px 30px;
}
As you can see, I am trying to put dynamic header text by using {{ headerTExt }} by setting it inside my Template file with variable {% set headerTExt = 'asdf' %} but its not working. If I put static text, its working but dynamic not working.
Can someone guide me how can I make it work
You're looking for {% placeholder %}: https://octobercms.com/docs/markup/tag-placeholder
Template File:
{% put headerText %}Test{% endput %}
Layout File:
<html>
<head>
// etc
</head>
<body>
<div id="header">
{% placeholder 'headerText' %}
</div>
</body>
</html>

Cannot open view in laravel

Good day. I recently learn about laravel. Then, i'm trying to fetch data from database (I'm using Sqlsrv) But i face an error
htmlspecialchars() expects parameter 1 to be string, object given
(View: D:\xampp\htdocs\boby\resources\views\welcome.blade.php)
Here is my script
routes/web.php
Route::get('/', function () {
$datauser = DB::table('users')->get();
return view('welcome',compact('datauser'));
});
and my view is like this (like welcome.blade.php)
<!doctype html>
<html lang="{{ config('app.locale') }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Raleway', sans-serif;
font-weight: 100;
height: 100vh;
margin: 0;
}
.full-height {
height: 100vh;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}
.position-ref {
position: relative;
}
.top-right {
position: absolute;
right: 10px;
top: 18px;
}
.content {
text-align: center;
}
.title {
font-size: 84px;
}
.links > a {
color: #636b6f;
padding: 0 25px;
font-size: 12px;
font-weight: 600;
letter-spacing: .1rem;
text-decoration: none;
text-transform: uppercase;
}
.m-b-md {
margin-bottom: 30px;
}
</style>
</head>
<body>
<ul>
#foreach ($datauser as $user)
<li> {{ $user }} </li>>
#endforeach
</ul>
</body>
</html>
how can handle this error ? thanks in advance
You can't display an object like that. You need to fetch the properties when displaying.
<li> {{ $user->id }} </li>>
<li> {{ $user->name }} </li>>
<li> {{ $user->email }} </li>>
You can use the {{}} to display object.
in the foreach , $user is an object ,
if you want to show user's email, use it {{ $user->email }}

Render a partial view with layout in Zend Framework 1.12

Similar questions have been asked before but unfortunately I am still not able to find a solution of my problem.
I want to render a view with its layout and store its response into a variable.
I have an action called pdf as shown below.
public function pdfAction(){
$ids = $this->getParam('id');
$entity = $this->getParam('entity');
$referer = $this->getRequest()->getServer('HTTP_REFERER');
if(empty($ids) || empty($entity)){
$this->_helper->redirector->gotoUrlAndExit($referer);
}
$grid = $this->_exportModel->getExportGrid($ids, $entity);
if(empty($grid->data[0])){
$this->_helper->messenger->error('No user was found for the given id. Please pass the correct parameters and try again.');
$this->_helper->redirector->gotoUrlAndExit($referer);
}
/* I would like to render the view here and get its response below. */
$html = '';
$pdf = new Om_PDF();
$pdf->writeHtmlToPDF($html);
}
This is the pdf view for the above action.
<?php echo $this->render('templates/grid/print-grid.phtml'); ?>
And here's the pdf layout
<?php echo $this->doctype(); ?>
<html moznomarginboxes mozdisallowselectionprint>
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" media="all"/>
<style type="text/css">
.container {
margin: 0 auto;
max-width: 1000px;
text-align: center;
margin-top: 30px;
}
#media print {
#page {
size: auto;
margin: 15mm 10mm 15mm 10mm;
}
body {
margin: 0px;
}
.page-break {
display: block;
page-break-before: always;
}
.print-view-table {
float: left;
width: 45% !important;
margin-right: 5%;
}
.print-view-table tr th, .print-view-table tr td {
width: 30%;
}
.print-view-table tr th {
background-color: #e0e0e0 !important;
border: 1px solid #ddd;
-webkit-print-color-adjust: exact;
}
}
</style>
<head>
<?php ?>
</head>
<body>
<div class="container">
<div class="row">
<?php echo $this->layout()->content; ?>
</div>
</div>
</body>
</html>
So far I have tried using render() and partial() methods but none of them worked.
Is there a way using which I can get the out put of the pdf view along with its layout inside the pdfAction() method?
You need to use :
$this->_helper->layout->setLayout('/path/to/your/pdf_layout_script');
in your pdfAction() and after that you can use render() or partial() methods, the corrects layout should be out put

trying to display datatable in laravel project undefined variable table

I am trying to follow a tutorial found here :
http://wern-ancheta.com/blog/2014/08/10/using-datatables-with-laravel/ to incorporate datatables into my laravel but have encountered the following error
Undefined variable: table (View: C:\xampp\htdocs\laravel\awsconfig\app\views\search.blade.php
here is my controller :
<?php
class HomeController extends BaseController {
protected $layout = 'search';
public function users(){
$table = Datatable::table()
->addColumn('instanceId',
'imageId',
'privateDnsName',
'publicDnsName',
'keyName',
'instanceType',
'launchTime',
'kernelId',
'subnetId',
'vpcId',
'privateIpAddress',
'publicIpAddress',
'architecture',
'rootDeviceType',
'rootDeviceName',
'virtualizationType',
'sourceDestCheck')
->setUrl(route('instance.search'))
->noScript();
$this ->layout->content = View::make('search', array('table' => $table));
}
}
and my view :
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AWS Config Search</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.9.4/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/datatables/1.9.4/css/jquery.dataTables.min.css">
<style>
#import url(//fonts.googleapis.com/css?family=Raleway:700);
body {
margin:0;
font-family:'Raleway', sans-serif;
text-align:center;
color: #3a3a3d;
}
.welcome {
width: 300px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -100px;
}
a, a:visited {
text-decoration:none;
}
h1 {
font-size: 32px;
margin: 16px 0 0 0;
}
</style>
</head>
<body>
<div class="row">
<div class="col-md-12">
<h3>AWS Configuration</h3>
{{ $table->render() }}
{{ $table->script() }}
</div>
</div>
#stop
</body>
</html>
any help would be greatly appreciated
try using
View::make('search')->with('table', $table);

Categories