Code Monkey home page Code Monkey logo

Comments (5)

askme-gpt avatar askme-gpt commented on May 20, 2024 1

@jorgecc yes ,i know ,thank you very much . I found a solution before you publish the YAF wiki , and I make yaf templete just like laravel. here is my code:

D:\phpStudy\PHPTutorial\WWW\yaf_test\application\library\BladeCache.php

<?php
use eftec\bladeone\BladeOne;
use eftec\bladeone\BladeOneCache;

class BladeCache extends BladeOne
{
    use BladeOneCache;
}

D:\phpStudy\PHPTutorial\WWW\yaf_test\application\library\BladeAdapter.php

<?php

use eftec\bladeone\BladeOne;

class BladeAdapter implements Yaf\View_Interface
{

    public $_blade;

    /**
     * Constructor
     *
     * @param string $tmplPath
     * @param array $extraParams
     * @return void
     */
    public function __construct()
    {
        $bladeConfig = Yaf\Registry::get("config")->get("blade")->toarray();
        $views       = $bladeConfig['template_dir'] ?? '';
        $cache       = $bladeConfig['cache_dir'] ?? '';
        // 使用缓存
        $this->_blade = new BladeCache($views, $cache);

        // 不使用缓存
        // $this->_blade = new BladeOne($views, $cache, BladeOne::MODE_AUTO);
        $this->_blade->setInjectResolver(function ($className) {
            // Custom logic for resolving
            return new $className();
        });

        // 全局变量
        // $this->_blade->share('lang', 'test');

        foreach ($bladeConfig as $key => $value) {
            $this->_blade->$key = $value;
        }
    }

    /**
     * Set the path to the templates
     *
     * @param string $path The directory to set as the path.
     * @return void
     */
    public function setScriptPath($path)
    {
        if (is_readable($path)) {
            $this->_blade->template_dir = $path;
            return;
        }

        throw new Exception('Invalid path provided');
    }
    /**
     * Retrieve the current template directory
     *
     * @return string
     */
    public function getScriptPath($request = null)
    {
        return $this->_blade->template_dir ?? null;
    }

    public function assign($name, $value = null)
    {
        return true;
    }

    public function render($view_path, $tpl_vars = null)
    {
        return true;
    }

    public function display($view_path, $tpl_vars = null)
    {
        echo $this->_blade->run($view_path, $tpl_vars);
    }

    public function getView()
    {
        return $this->_blade;
    }
}

common helper function:

function view($view_path, $tpl_vars = [])
{
    $blade = new BladeAdapter();
    return $blade->display($view_path, $tpl_vars);
}

then i use blade one in my app like below:

    public function readAction()
    {
        $id   = $this->getRequest()->getQuery('id');
        $data = $this->article->articleInfo($id);
        return view('article.read', $data);
    }

application.ini

[common]
application.directory = APPLICATION_PATH  "/application"
application.dispatcher.catchException = TRUE
application.view.ext=blade.php

[product : common]
blade.template_dir     = APPLICATION_PATH "/application/views/"
blade.cache_dir        = APPLICATION_PATH "/application/cache/"

I directly return true in render and assign ,because I don't need the two function , and my app work well. by the way ,when we use bladeone in other unlike laravel , mostly we can set suffix of templete and the left-right quotes , so we can use plugins in code editor, just use laravel blade snippets.
thank you reply so quickly.

from bladeone.

jorgecc avatar jorgecc commented on May 20, 2024

Ok, let's me see it.

from bladeone.

jorgecc avatar jorgecc commented on May 20, 2024

Added on 3.23

from bladeone.

askme-gpt avatar askme-gpt commented on May 20, 2024

@jorgecc how to use share global variables in blade one ? I am using yaf framework

from bladeone.

jorgecc avatar jorgecc commented on May 20, 2024

Hi there:

Did you know that you could open a new issue?. It is for free ;-)

Anyways, here it goes:

https://github.com/EFTEC/BladeOne/wiki/Using--BladeOne-with-YAF

from bladeone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.