Я достиг этого, используя всего лишь два шага:
Шаг 1: перейдите в AndroidManifest.xml и добавьте параметр в тег - android: parentActivityName = ". home.HomeActivity"
example:
<activity
android:name=".home.ActivityDetail"
android:parentActivityName=".home.HomeActivity"
android:screenOrientation="portrait" />
Шаг 2: в ActivityDetail добавьте действие для предыдущей страницы / активности
:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
Небольшая модификация приведенного выше сценария. Вы можете использовать эту функцию внутри любого класса без расширения класса BladeCompiler.
public function bladeCompile($value, array $args = array())
{
$generated = \Blade::compileString($value);
ob_start() and extract($args, EXTR_SKIP);
// We'll include the view contents for parsing within a catcher
// so we can avoid any WSOD errors. If an exception occurs we
// will throw it out to the exception handler.
try
{
eval('?>'.$generated);
}
// If we caught an exception, we'll silently flush the output
// buffer so that no partially rendered views get thrown out
// to the client and confuse the user with junk.
catch (\Exception $e)
{
ob_get_clean(); throw $e;
}
$content = ob_get_clean();
return $content;
}
Я не использую лезвие таким образом, но я думал, что метод компиляции принимает только представление как аргумент.
Возможно, вы ищете:
Blade::compileString()
Это старый вопрос. Но я нашел пакет, который облегчает работу.
Компилятор String Laravel Blade String отображает шаблоны клинков из строкового значения. Проверьте документацию о том, как установить пакет.
Вот пример:
$template = '<h1>{{ $name }}</h1>'; // string blade template
return view (['template' => $template], ['name' => 'John Doe']);
Я нашел решение, расширив BladeCompiler.
<?php namespace Laravel\Enhanced;
use Illuminate\View\Compilers\BladeCompiler as LaravelBladeCompiler;
class BladeCompiler extends LaravelBladeCompiler {
/**
* Compile blade template with passing arguments.
*
* @param string $value HTML-code including blade
* @param array $args Array of values used in blade
* @return string
*/
public function compileWiths($value, array $args = array())
{
$generated = parent::compileString($value);
ob_start() and extract($args, EXTR_SKIP);
// We'll include the view contents for parsing within a catcher
// so we can avoid any WSOD errors. If an exception occurs we
// will throw it out to the exception handler.
try
{
eval('?>'.$generated);
}
// If we caught an exception, we'll silently flush the output
// buffer so that no partially rendered views get thrown out
// to the client and confuse the user with junk.
catch (\Exception $e)
{
ob_get_clean(); throw $e;
}
$content = ob_get_clean();
return $content;
}
}
$myBlade = new MyBlade(App::make('files'), App::make('path').'/storage/views');
– Felice Ostuni
5 February 2014 в 11:45