Laravel blade template engine :cannot see html contents in page - php

I am trying to integrate blade template engine in CodeIgniter framework using library method.
Here are the steps I followed
1.Download the blade template engine via composer and copy to application/libraries folder.
2.Created a class named Bladetemplate in libraries folder
Bladetemplate.php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once dirname(__FILE__).'/blade/vendor/autoload.php';
use Philo\Blade\Blade;
class Bladetemplate {
public function loadTemplate(){
$views = APPPATH. '\views';
$cache = APPPATH. '\cache';
$blade = new Blade($views, $cache);
return $blade;
}
}
3.In my controller file, I've loaded the library and call the function loadTemplate for blade template view
public function index()
{
$this->load->library('Bladetemplate');
//template object
$obj= $this->bladetemplate->loadTemplate();
$obj->view()->make('test',array('data'=>'test'))->render();
}
In my applications/views folder file named test.blade.php is present
There is no error is shown, but nothing displayed on the page ( some HTML contents are present).

Change your view file name to add .blade. Like if your view file test.php than make it test.blade.php
Instead of $obj->view()->make('test',array('data'=>'test'))->render();
you need to use $obj->view()->make('test.blade',array('data'=>'test'))->render();
Whenever you are using blade template, you have to render your view as blade type. So, test.blade
I hope, It will work.
If not, let me know.

Related

Codeigniter 3: load a mobile specific view

I have put together a CRUD application with CI 3. I am trying to load a mobile specific template (view) for the homepage. For this purpose I have:
1) Loaded the user_agent library:
$autoload['libraries'] = array('database', 'form_validation', 'user_agent');
2) Created a directory called mobile in the views directory and a home.php view file inside it.
3) The Home controller looks like this:
class Home extends CI_Controller {
public function index() {
$this->load->model('Customer');
$customers = $this->Customer->getCustomers();
if ($this->agent->is_browser()) {
$this->load->view('home', ['records'=>$customers]);
} else {
$this->load->view('mobile/home', ['records'=>$customers]);
}
}
}
The error I get is:
Failed opening required 'includes/header.php'
NOTE: At the top of my view files I have:
<?php require "includes/header.php"; ?>
The includes directory is directly in the views directory so I believe the first thing to do is use the application's root in the path above.
How do I do that?
try $this->load->view("includes/header"); instead of require includes/header.php;

Can't find the true url in a php project using Yii2

I'm new in php coding and I'm using Yii2 framework
I'm trying to make a simple project as follow:
I added a .php file named "PostController.php" in the backend/controllers and I wrote this codes in this file:
<?php
namespace backend\controllers;
use yii\web\Controller;
class PostController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
}
?>
and I created a file in beckend/views named "post" and in this folder I created a.php file named index.php
then I just wrote one line in index.php for test as bellow:
<h1>Hello World</h1>
Now I want to see this index file (Hello World) in my browser. Which url I should enter in my browser to see that? I tried the bellow url and it didn't worked!:
projectname.loc/index.php?r=post/index
if pretty url is true then you have to access the controller like
localhost/projectname/backend/web/index.php/controller/action
if pretty url is false then you have to access the controller like
localhost/projectname/backend/web/index.php?r=controller/action
if you project is in your local machine, if its on your server then you have to write server name instead of localhost
You should go to projectname.loc/post (or projectname.loc/post/index), to be in this action. before that you have to turn on the "prettyUrl" in your urlManager
If you use basic tamplate from yii2 your namespace must be app/backend/controllers and you should go to projectname.loc/index.php?r=backend/post/index
"backend" it will be a path to your controller, not a module

Map controller and view (Suit CRM 7.7.8)

I am very new to SugarCRM (SuitCRM 7.7.8). I could create a controller and could echo some strings in it. I wanted to make that value in a view file. I got confused whether I should use some js files or some tpl view file.
This is my code:
<?php
class MymoduleController extends SugarController {
//Can now put actions here
public function action_convert(){
echo "Hello world!";
//return true;
exit;
}
}
How can I map the controller to a view file.
In your controller action method add the following:
$this->view = 'EditView'
Change the 'EditView' to the view you wish to use. The built in MVC stuff is kept in include/MVC and the include/ListView, include/EditView, and include/MVC/DetailView.
If you take a look at say module/Accounts/views. You can see how views are implemented. It is best to create your code in the custom/modules/[module] folder. As this ensures that your changes will not be overwritten when you upgrade SuiteCRM.
You should separate your html with your view using tpls.
if you add the following in the display method of your view:
function display(){
$template = new Sugar_Smarty();
$template->assign('APP', $app_strings);
$template->assign('MOD', $mod_string);
echo $template->fetch('include/ListView/ListViewGeneric.tpl');
}
you can load your custom views.

How to navigate controller folder using create URL

The controller:
controllers
|-SiteAction(folder)
|-1700(folder)
|-Participate.php
|-SiteController
How to render Participate.php class using CreateUrl?
<?=$this->createUrl('siteActions/1700/participate/'?>
is this code write?

codeigniter issue with loading view from controller

I am new to codeigniter and really interested in trying it out. I followed the guide but ran into a problem. It seems like I am unable to load my first page properly.
I have inside the view folder another folder called general and inside it index.php.
in controller folder, I have sub-folder with general and inside it is Default controller.
I have the following route and yet the page showing is blank
$route['default_controller'] = "general/default";
$route['404_override'] = '';
When I visit the link, I type this in browser:
http://localhost:8888/treventa/
and the screen is blank. Am I doing something wrong? Sorry if this is too simple but a person got to learn from his mistake :)
Try with me step by step:
Firstly: the Controller:
(main.php) File content
if (!defined('BASEPATH'))exit('No direct script access allowed');
class Main extends CI_Controller {
public function index() {
$this->load->view('general/welcome');
}
}
Secondly: The view:
(welcome.php) File content
You can put anything you want
<h1> Hello, I'm the view file </h1>
Finaly: The routes:
(routes.php) File content
$route['default_controller'] = "general/main";
Now call the script like this http://localhost/codeIgniter/, that's where codeIgniter is the script folder name.
I think everything now is clear.
CI trying to use method default() of general controller. If You want to use folders for controllers, make sure You specify method, so try $route['default_controller'] = "general/default/index";
And one more thing: this method (default_controller) will be used when You trying reach Your root http://localhost:8888/, if You want to route request from http://localhost:8888/treventa/ to default controller, You need to add route-rule to /config/routes.php something like $route['treventa'] = "general/main/index";

Categories