Jenssegers Blade Template Engine - page render error - template-engine

I have views folder and my pages in views folder ( ex : home.blade.php,
test.blade.php) , I want to do page orientation but I have some error :
<?php
require 'vendor/autoload.php';
use Jenssegers\Blade\Blade;
$page= isset($_GET['p']) ? $_GET['p'] : 'home';
$blade = new Blade('views', 'cache');
echo $blade->make('home');
$pages = array('home' =>["views" => 'home.blade.php'],
'test' =>["views" => 'test.blade.php']);
echo array_key_exists($page,$pages) ? $blade->render($pages[$page]
['views']) : $blade-> render('404.blade.php');
?>
Error:
Fatal error: Uncaught InvalidArgumentException: View [home.blade.php]
not found. in
/var/www/html/vendor/illuminate/view/FileViewFinder.php:137 Stack
trace:
#0

You have to change your views name home.blade.php to home. Otherwise it considers it as directory hierarchy home->blade->php. In other words it's searching for a file with name php.blade.php, php.php or php.css under home/blade/ directory.
$pages = array('home' =>["views" => 'home'],
'test' =>["views" => 'test']);

Related

Trying to include template in the error 404 page

Im trying to get a error 404 page in the template which Im using, but it's not working. I have tried MY_Exceptions also.
There is view page called error404 and code goes like this:
<h1><?php echo $heading;?></h1>
<?php echo $message; ?>
Just to display error msg.
Im trying to include the below line to display error in my template, but it's throwing error:
$this->load->view("pages/template.php");
What should I do to display customized error 404 in my template using codeigniter.
It should be like this, and pass message and heading like this :
$data['heading'] = 'heading';
$data['message'] = 'your message';
$this->load->view("pages/template",$data);
instead of this
$this->load->view("pages/template.php");
Your view template.php:
<h1><?php echo $heading;?></h1>
<?php echo $message; ?>
for more :https://www.codeigniter.com/user_guide/general/views.html#adding-dynamic-data-to-the-view

Why Codeigniter3.0's url can't be blank after doamin name?

I'm corrently develop webs application for selling products online by using Codeigniter and upgrade from Ci2.2.1 to CI3.0.
However I've meet an errors 404 Page Not Found when I enter domain name on url not yet called any controller by hoped default_controller will load instead of type my main controller.
Notes: It is working on Ci2.2.1 and it stop work when upgrade to CI3.0.
It is working if I type any characters or any Controller after domain name(http://localhost/Ecom3/sometroller) But it is coudn't call default_controller and keep empty or blank after domain (http://localhost/Ecom3/).
Errors log: ERROR - 2015-04-24 03:48:57 --> 404 Page Not Found: /index
Please check my webs structure below:
Main->Main_controller->MY_controller->CI_Controller
My purpose to make it easy to controller the templates.
In MY_controller I've use __autoload() function
function __autoload($class){
if (strpos($class, 'CI_') !== 0)
{
if (file_exists($file = APPPATH . 'libraries/' . $class .'.php'))
{
include_once $file;
}
}
}
And I have confige route as below
$route['default_controller'] = "main/Main";
$route['(:any)'] = 'main/main/index/$1';
$route['c'] = 'cat/cat/index/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
The problem:
My url can't be blank after I type domain or after forword slash as below image
Please help
I try your code and get 404 when Main.php in your controller place inside controller/main folder. but when im move Main.php into controller folder, default controller to Main has working. then im try to debuging and see:
// Is the method being specified?
if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2)
{
$method = 'index';
}
in core/Router.php
thats mean codeigniter3 are not allowed you to set default_controller in sub folder. you must put default_controller in app/controller/ to make it works.
in config/router.php
change this:
$route['default_controller'] = "main/Main";
TO:
$route['default_controller'] = "Main";
then move your controller file :
app/controller/main/Main.php
TO
app/controller/Main.php

Migrating from Joomla 2.5 to 3x Generating Errors

Trying to migrate some of the custom components which works well in Joomla 2.5.14 to Joomla 3.1.5, however getting some errors like - 404 component not found in Joomla Backend & other errors in frontend
Is there any migration guide from Jooma 2.5 to 3x series, of what changes need to be done in custom components
Front End Section of Site
1st error
Notice: Use of undefined constant DS - assumed 'DS' in forms.php
2nd error
Warning: require_once(com_formsDScontroller.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in forms.php
3rd error
Fatal error: require_once() [<a href='function.require'>function.require</a>]: Failed opening required 'com_formsDScontroller.php' (include_path='.;C:\php\pear') in forms.php
Been all errors showing forms.php, it is
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once( JPATH_COMPONENT.DS.'controller.php' );
if ($controller = JRequest::getWord('controller')) {
$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
if (file_exists($path)) {
require_once $path;
} else {
$controller = '';
}
}
$classname = 'FormsController'.$controller;
$controller = new $classname();
$controller->execute( JRequest::getVar( 'layout' ) );
$controller->redirect();
?>
Add the below line
defined( '_JEXEC' ) or die( 'Restricted access' );
if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
From the docs
The DS constant has been removed. If you really need it you can use
DIRECTORY_SEPARATOR instead.
Similar Question

How to call only one item from array with $this->config->item CODEIGNITER?

I have a default config file in my config directory (default.php). I've loaded it already with autoload file:
$autoload['config'] = array('default');
there is my default.php:
<?php
//$config['secretUserHashKey'] = 'g81h6JH18kASPkgAW16jS132sa186h1';
//$config['secretPhotoNameHashKey'] = 'ghOH3Hs841s98sssp1AHDWPfMHAjd';
// Pages
$config['pagesUrl'] = array(
'home' => 'homepage',
'login' => 'loginsite'
);
and how I should use it on my view?
<li>Home <span class="divider">/</span></li>
with this example I can get value if mine string is'nt array:
$config['home'] = 'homepage';
so what should I do to grab item from my array?
Try this:
<?php echo $this->config->item('home', 'pagesUrl');?>
I prefer this way:
$api_config = ci()->config->item('api');
if (isset($api_config['api_server']))
...
or in your case:
$pagesUrl_config = ci()->config->item('pagesUrl');
if (isset(pagesUrl['home']))
...
or in the view:
<?= #base_url(#ci()->config->item('pagesUrl')['home'])?>
this should do the trick
$this->config->config['pagesUrl']['home']
$this->config->item('item_name');
https://www.codeigniter.com/userguide3/libraries/config.html

How can I load my mustache template with PHP?

index.php:
<!-- language: lang-php -->
require('v/Mustache/Autoloader.php');
Mustache_Autoloader::register();
$m = new Mustache_Engine(array(
'loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/v'),
));
// loads template from `v/sign_in.mustache` and renders it.
$m->render('sign_in', array('planet' => 'world'));
?>
v/sign_in.mustache:
<h1>Where in the {{planet}} is Carmen San Diego?</h1>
When I load index.php, I see a big blank screen with no errors.
echo $m->render('sign_in', array('planet' => 'world'));

Resources