问题是,当字符串包含单词'或'和'like'的组合时,活动记录语句中的字符串会被转义。这是我使用的代码
main.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Agency - Start Bootstrap Theme</title>
<!-- Bootstrap Core CSS -->
<link href="<?php echo asset('vendor/bootstrap/css/bootstrap.min.css');?>" rel="stylesheet">
<!-- Custom Fonts -->
<link href="<?php echo asset('vendor/font-awesome/css/font-awesome.min.css');?>" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Kaushan+Script' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,100,300,700' rel='stylesheet' type='text/css'>
<!-- Theme CSS -->
<link href="<?php echo asset('css/agency.min.css');?>" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body id="page-top" class="index">
@include('layouts.partials._navigation')
@include('layouts.partials._header')
@yield('content')
@include('layouts.partials._footer')
</body>
</html>
_navigation.blade.php
<!-- Navigation -->
<nav id="mainNav" class="navbar navbar-default navbar-custom navbar-fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span> Menu <i class="fa fa-bars"></i>
</button>
<a class="navbar-brand page-scroll" href="#page-top">Start Bootstrap</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="hidden">
<a href="#page-top"></a>
</li>
<li>
<a class="page-scroll" href="#services">Services</a>
</li>
<li>
<a class="page-scroll" href="#portfolio">Portfolio</a>
</li>
<li>
<a class="page-scroll" href="#about">About</a>
</li>
<li>
<a class="page-scroll" href="#team">Team</a>
</li>
<li>
<a class="page-scroll" href="#contact">Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
_header.blade.php
<header>
<div class="container">
<div class="intro-text">
<div class="intro-lead-in">{{$myname}}!</div>
<div class="intro-heading">my location {{$mylocation}} date : {{date('m')}}</div>
<a href="#services" class="page-scroll btn btn-xl">Tell Me More</a>
</div>
</div>
</header>
_footer.blade.php
<!-- jQuery -->
<script src="<?php echo asset('vendor/jquery/jquery.min.js');?>"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<?php echo asset('vendor/bootstrap/js/bootstrap.min.js');?>"></script>
<!-- Plugin JavaScript -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
<!-- Contact Form JavaScript -->
<script src="<?php echo asset('js/jqBootstrapValidation.js');?>"></script>
<script src="<?php echo asset('js/contact_me.js');?>"></script>
<!-- Theme JavaScript -->
<script src="<?php echo asset('js/agency.min.js');?>"></script>
child page that i need to inherit master page
@extends('layouts.main')
@section('content')
<!-- Services Section -->
<section id="services">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Services</h2>
<h3 class="section-subheading text-muted">Lorem ipsum dolor sit amet consectetur.</h3>
</div>
</div>
<div class="row text-center">
<div class="col-md-4">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-shopping-cart fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">E-Commerce</h4>
<p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima maxime quam architecto quo inventore harum ex magni, dicta impedit.</p>
</div>
<div class="col-md-4">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-laptop fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">Responsive Design</h4>
<p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima maxime quam architecto quo inventore harum ex magni, dicta impedit.</p>
</div>
<div class="col-md-4">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-lock fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">Web Security</h4>
<p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima maxime quam architecto quo inventore harum ex magni, dicta impedit.</p>
</div>
</div>
</div>
</section>
@endsection
这适用于普通字符串但在$ phrase遇到类似字符串时失败 '点击您想要使用的活动或预订代码。' 其中'或'和'喜欢'作为单词出现。
结果查询将类似于
$this->db->select('id');
$this->db->where('phrase', $phrase);
$this->db->from('phrases');
$ret = $this->db->get();
我无法禁用转义,因为这对其他字符串很方便。
答案 0 :(得分:0)
我认为您需要在where子句中添加第三个参数来转义值。
$this->db->select('id');
$this->db->where('phrase', $phrase, FALSE);
$this->db->from('phrases');
$ret = $this->db->get();
来自manual:
其中($ key [,$ value = NULL [,$ escape = NULL]])
参数:
$ key(mixed) - 要比较的字段名称或关联数组$ value(混合) - 如果是单个键,则与此值相比
$ escape(bool) - 是否转义值和标识符
此帖子中的更多信息Stack overflow。