小编Sai*_*akR的帖子

Yii2页面标题不是从另一个类tha控制器继承控制器

在我的控制器的 action 中,页面标题可能设置如下:

$this->view->title .= ' | Some title';
Run Code Online (Sandbox Code Playgroud)

问题在这里,它似乎没有整个应用程序的默认标题。即我的站点名称 | 页面标题。

我目前知道的唯一工作方法是创建另一个从该类继承的控制器类,controller$this->view->title 在构造方法中定义或设置它,然后从这个类继承我的所有控制器,如下所示:

namespace common\controllers
use Yii;
use yii\web\Controller;

class MainController extends Controller
{
   function __construct()
   {
     $this->view->title = 'My site name ';
   }
}
Run Code Online (Sandbox Code Playgroud)

然后在任何控制器中,我应该从MainController.

问题是:

是否有任何配置方式或引导方式为页面标题设置默认值,然后我可以通过操作将另一个值连接到它?

php inheritance yii2

1
推荐指数
1
解决办法
4241
查看次数

Javascript正则表达式中的特定阿拉伯单词

我需要从字符串中替换特定的阿拉伯单词,例如,??在其之前或之后使用任何变化的空白字符.我使用以下正则表达式:

/\s*(??)\s*/
Run Code Online (Sandbox Code Playgroud)

它适用于Regex101 DEMO.但是,这个正则表达式似乎在Javascript代码中不起作用,如下所示:

txt1 = txt.replace(/\s*(??)\s*/ig,inpt)
Run Code Online (Sandbox Code Playgroud)

我试图使用RegExp对象,如:

f = "/\s*(??)\s*/ig"
r = new RegExp(f)
txt1 = txt1.replace(r,inpt);
Run Code Online (Sandbox Code Playgroud)

最后,我知道的Javascript正则表达式不读Unicode字符,我试图字译码器??f = "/\s*(u\1589-u\1581)\s*/i",但也没有结果.在这里,我不是在询问角色的课程.我只是用一个特定的词来表示.

编辑

使用rsnipet:

txt1 = txt.replace(' ??',inpt);
     if (txt1 == txt){
       f = "/\s*(??)\s*/ig"
       r = new RegExp(f)
       txt1 = txt1.replace(r,inpt);

     }
Run Code Online (Sandbox Code Playgroud)

javascript regex arabic

0
推荐指数
1
解决办法
772
查看次数

Laravel 5 Auth在Controller构造中不是对象

app\Http\Controller其中有一个名为Controller所有其他控制器继承的主控制器类.在任何其他控制器中,以下代码正常工作:

class OtherController extends Controller{

   public function index(){
      dd(\Auth::user()->id);
   }
} 
Run Code Online (Sandbox Code Playgroud)

但是,在Controller.php父类中,当我尝试在construct方法中执行类似的操作时,我尝试获取非对象错误的属性:

class Controller extends BaseController {

    use AuthorizesRequests,
        DispatchesJobs,
        ValidatesRequests;
    public $foo = 'null';

    public function __construct() {
        $this->middleware('auth');
        dd(\Auth::user()->id);//Error is here.
        dd(\Route::getCurrentRoute()->action['controller']);

    }

}
Run Code Online (Sandbox Code Playgroud)

我怎么能解决这个问题?

php laravel-5 laravel-5.4

0
推荐指数
1
解决办法
1491
查看次数

如何在jquery中调用$(function)

我有以下功能:

$(function(){
    performance();
    function performance(){
       pHandler = setTimeout(performance,3000)
        perOb = [];
        alert('hhhh')
        $(".performance").each(function(i){            
            perOb[i] = $(this);
            url = '/cavity/performance/'+perOb[i].attr('data-id')+'/'+jobId;
            //perOb[i].html('%');
            $.ajax({
                type: "GET",
                //dataType: "json",
                url: url,
                success: function(data){
                    perOb[i].html(data.performance+"%");
                },
                error: function(xhr, status, response){
                    console.log(xhr.responseText);

                },

            });
        });
    }

});
Run Code Online (Sandbox Code Playgroud)

我试图从另一个事件中调用它,如下所示:

$('#in-between').change(function(){
        if ($(this).prop('checked')){
            window.clearTimeout(pHandler);
            alert('yesr')            
        }
        else{
            alert('noo')
            performance();
        }

    })
Run Code Online (Sandbox Code Playgroud)

我有错误performance is not a function.我试过了$.performance(),jQuery.performance()我也尝试将它分配给变量,如:

perf = $(function(){
    performance();
    function performance(){
       pHandler = setTimeout(performance,3000)
     .......
Run Code Online (Sandbox Code Playgroud)

并将其称为perf.performance() 但所有尝试的人都没有成功地从事件中调用它.

此问题与JavaScript错误不同 …

javascript jquery

0
推荐指数
1
解决办法
49
查看次数

Laravel 自定义验证规则适用于不需要的空字段

我有必需的文件字段,它作为路径记录在数据库中。如果它在数据库中的字段为空,我想使它成为可选的必需项。在update我的控制器的操作中,我设置了以下验证:

$this->validate(request(),[
    'drawings' => 'requiredIfEmpty:'.$product->drawings.'|file|max:'. config('fox.photoMaxSize').'|mimes:pdf',
Run Code Online (Sandbox Code Playgroud)

然后在app/Providers/AppServiceProvider.php我定义的requiredIfEmpty验证器中:

Validator::extend('requiredIfEmpty',function ($attribute,$value,$parameters,$validator){
        if(is_null($parameters[0]) || empty($parameters[0])){
            if (is_null($value)){
                return false;
            }
        }
        return true;
    });

    Validator::replacer('requiredIfEmpty', function ($message, $attribute, $rule, $parameters) {
        return __('The :attr is required',['attr' => $attribute]);
    });
Run Code Online (Sandbox Code Playgroud)

在视图中,_form我使用表单助手,如下所示drawings

<div class="form-group {{$errors->first('drawings','has-error')}}">
    @if (!is_null($product->drawings))
    <a href="{{$product->drawings}}" target="_bfox"><img src="/imgs/pdf.png" alt="{{__('PDF File')}}" title="{{__('PDF File')}}" /></a>
    <br>
    @else
    <img src="/imgs/empty.png" width="64" height="64" alt="{{__('Empty')}}..." title="{{__('Empty')}}..." /> <br>
    @endif
    {!! Form::label('drawings', __('Drawings')) !!}        

        {!! Form::file('drawings',['class' …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5

0
推荐指数
1
解决办法
1823
查看次数

正则表达式为b,i和仅标签或字符串中没有

我想知道适合用于检查一个字符串,包括某些HTML标记,即可能的正则表达式,<b>,<i>并且<a>也没有任何标签.使用PHP preg_match.

例如:

"This a text only.." return true
"This is a <b>bold</b> text" return true
"this is <script>alert('hi')</script>" return false
"this is <a href="#">some</a>and <h1>header</h1>" return false
Run Code Online (Sandbox Code Playgroud)

php regex

-1
推荐指数
1
解决办法
86
查看次数

Concatenate PHP function output to a string like variables

For variable $x we can concatenate it to a string in many ways, one of them is like the following:

$x = "Hello";
echo "I say {$x} to all of you.";
// The output should be: I say Hello to all of you.
Run Code Online (Sandbox Code Playgroud)

However, If I tried to do something like this with a function, it will fail:

$x = "Hello";
echo "I say {strtolower($x)} to all of you.";
// The output should be: I say {strtolower(Hello)} to all of …
Run Code Online (Sandbox Code Playgroud)

php string string-concatenation

-1
推荐指数
1
解决办法
7372
查看次数