Adds: $data['customer_firstname'] = $this->customer->getFirstName(); in header.php
You may be something:
<?php
class ControllerCommonHeader extends Controller {
public function index() {
$data['customer_firstname'] = $this->customer->getFirstName();
Displays the name eg in header.tpl: <?php echo $customer_firstname ?>
Login to your store manager: go to extensions, modifications and upgrade (button top right).
Ready!
There are two header.tpl files inside OpenCart project. I think you are editing header.tpl inside public_html/catalog/controller/common/header.tpl ,so there is nothing will solve your problem editing this file.
go to the other location where second header.tpl file located. you can find it inside public_html/system/storage/modification/catalog/controller/common/header.tpl . in there you can get values by adding these,
$data['customer_firstname'] = $this->customer->getFirstName();
$data['customer_lastname'] = $this->customer->getLastName();
this will solve your problem.
try with this:
get customer information:
<?php
class ControllerCommonHeader extends Controller {
public function index() {
$customer_info = $this->model_account_customer->getCustomer($this->customer->getId());
$data['customer_firstname'] = $customer_info['firstname'];
The referenced post uses
$data['customer_firstname']
You should put your variable in the $data-Array to pass it to the template...
Adds: $data['customer_firstname'] = $this->customer->getFirstName(); in header.php
You may be something:
<?php
class ControllerCommonHeader extends Controller {
public function index() {
$data['customer_firstname'] = $this->customer->getFirstName();
Displays the name eg in header.tpl: <?php echo $customer_firstname ?>
Login to your store manager: go to extensions, modifications and upgrade (button top right).
Ready!
Related
I'm creating a webpage where students and teachers log in, teachers create levels and students can do that level.
I explain, I am using php with twig and I want to render a view passing parameters in a function. I've created a budle called Professors where I have the directory Controllers, Models and Templates.
In templates I have professors.html, where I show some information and a button to create a level for students, and also I have crearNivell.html, where the teacher will be able to create the level. When I'm in the page views professors my URL is this one:
When I click the button "CREATE LEVEL" I want my URL to be like this:
Instead I get this URL, and this one returns me an error.
In Controllers/ProfessorsController.php I have that code:
class ProfessorController extends Controller{
public function process($params)
{
/*var_dump($params);
die();*/
if(empty($params[0])){
$this->getProfessor(); //Here I return the view professor
}elseif(isset($params[0]) && $params[0] == "crearNivell"){
$this->twig = "crearNivell.html";
}
}
public function getProfessor(){
$this->twig = "professor.html";
}
}
Can someone help me with my code?
When I use var_dump() I get this:
and it should be like that:
I think what you're looking for is the API of Twig.
More specifically, you need the line below to render a template passing some parameters in array:
echo $template->render(['the' => 'variables', 'go' => 'here']);
If you use PHP the fastest way to "print" some content to the browser is echo, so don't hesitate to use it.
I found the answer to the questions a few days ago. I was complicating myself, it's just like this:
First you create the views, in Templates folder.
The $params are refered to the URL. For example:
alumne is the bundle
AlumneController.php
Then in AlumneController.php put the name of the views without the .html and you show it using $this->twig = "name_Of_The_View.html";
<?php
class AlumneController extends Controller{
public function process($params)
{
/*var_dump($params);
die();*/
if(empty($params[0])){
$this->getAlumne();
/*echo $usuari = $_SESSION["username"];*/
}else if(isset($params[0]) && $params[0] == "instruccions"){
$this->twig = "instruccions.html";
/*echo $usuari = $_SESSION["username"];*/
}else if(isset($params[0]) && $params[0] == "resultats"){
$this->twig = "resultats.html";
/*echo $usuari = $_SESSION["username"];*/
}
}
public function getAlumne(){
$this->twig = "alumne.html";
}
}
alumne.html
And in the button or link you are using to go to the page you write the path in Instruccions
<a class="mdl-navigation__link" href="alumne/instruccions">Instruccions</a>
<a class="mdl-navigation__link" href="alumne/resultats">Resultats</a>
I'm writing a prestashop module for prestashop 1.7.2.1.
I created a front controller for my module with the following code:
<?php
require_once (__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'php'.
DIRECTORY_SEPARATOR.'TuxInDb.php');
class TuxInModCarTypeCarTypeProductsModuleFrontController extends ModuleFrontController {
private $tuxDb;
public function initContent(){
parent::initContent();
$productIds = [];
$this->tuxDb = TuxInDb::getInstance();
$companyName = Tools::getValue('company_name');
$modelName = Tools::getValue('model_name');
$year = Tools::getValue('year');
$month = Tools::getValue('month');
$carType = Tools::getValue('car_type');
$carListCarTypeIds=$this->tuxDb->getCarListCarTypeIds($companyName,$modelName,$carType,$year,$month);
$productIds = $this->tuxDb->getProductIdsByCarListCarTypeIds($carListCarTypeIds);
$this->context->smarty->assign('product_ids',$productIds);
$this->setTemplate('module:tuxinmodcartype/views/templates/front/cartypeproducts.tpl');
}
public function setMedia() {
parent::setMedia();
$this->registerStylesheet('module-tuxinmodcartype-cartypeproducts-style','modules/'.$this->module->name.'/css/cartypeproducts.css');
$this->registerJavascript('module-tuxinmodcartype-cartypeproducts-js','modules/'.$this->module->name.'/js/cartypeproducts.js');
}
}
as you can see in setMedia() function I load a css and js files.
I even debugged it in xdebug and I noticed that those lines of code actually get executed, but when I try to browse my front controller with the following url:
http://prestashop.dev:8080/index.php?company_name=BMW&model_name=SERIA+1&year=2011&month=1&car_type=5+%D7%93%D7%9C%D7%AA%D7%95%D7%AA+%28%D7%94%D7%90%D7%A6%D7%B3%D7%91%D7%A7%29&fc=module&module=tuxinmodcartype&controller=cartypeproducts&id_lang=1
and I check the network tab of my google chrome browser I noticed that the js and css file I required do not get loaded.
any ideas?
I see no javascript errors or php errors (I also have DEV enabled in prestashop).
If an asset path is wrong then Prestashop won't even append it to the browser's <head> (or bottom depending on CCC settings) and won't throw out any errors.
Probably your path is incorrect, to get proper path use this:
$this->registerStylesheet('module-tuxinmodcartype-cartypeproducts-style', $this->module->getPathUri() . 'css/cartypeproducts.css');
$this->registerJavascript('module-tuxinmodcartype-cartypeproducts-js', $this->module->getPathUri() . 'js/cartypeproducts.js');
This works well with PrestaShop 1.7.x
Add this inside your ModuleFrontController:
public function setMedia()
{
parent::setMedia();
$this->addCSS($this->module->getPathUri().'views/css/style.css');
}
I hope this helps!
I have a controller named 'Student' with two actions called 'index' and 'add'.
I want to load different css files for each of the action. So far i have tried is, i have imported Html Helper, created object of it and called its css method. When i run it, it is not throwing any error, nor showing expected result. Means, it is not loading css file dynamically in my view.. How can i dynamically load css files in different views from Controller?
Code:-
<?php
App::import('Helper','Html');
class StudentController extends AppController
{
public function index()
{
// $current_controller = $this->params['controller'];
// echo $current_controller;
//$view=new View(new Controller($current_controller));
//$Html=new HtmlHelper($view);
$Html=new HtmlHelper(new View(null));
//$html=new HtmlHelper(new View());
$Html->css('cake.generics');
//echo ;
//$this->Html->css("cake.generics");
}
public function add()
{
// $current_controller = $this->params['controller'];
// echo $current_controller;
$html=new HtmlHelper(new View(null));
$html->css("mystyle.css");
}
}
You can do it in view file e.g
//in your View/Students/add.ctp
$this->Html->css('yourstyle', array('block' => 'yourStyle'));
//in your layout file
echo $this->fetch('yourStyle');
the same with js files
// in your view
$this->Html->script('yourjs', array('block' => 'yourJs'));
//in your layout file
echo $this->fetch('yourJs');
you can also create a global layout file in View > Element like default_assets.ctp
after that add this file in your default layout file like,default_layout.ctp in View > Layout folder
and after access this in your controller like
public function index(){
$this->layout = "default_layout";
}
I got it working in this way,
I have added "mycss" variable in controller, index action:-
$this->set('mycss','custom');
And accessed this mycss variable from layout file:-
if(isset($mycss)){
$this->Html->css("$mycss");
}
And it worked.
I have a multistore environment on a prestashop. I created a module with a controller to change store if postal code is not correct. The problem comes when I use Tools::redirect($newUrlToRedirect); it redirects to my current store, and I need it redirects to another store. This is my code:
class cartportkeyDeriverModuleFrontController extends ModuleFrontController {
public function init(){
//I am in the url http://localhost/shopgroup/shopnameCART/quick-order and
//check the postal code, then clicking a link I go to the URL
//http://localhost/shopgroup/shopnameNEW/index.php?fc=module&module=cartportkey&controller=deriver&id_cart=XXX&id_shop=YYY
parent::init();
$id_cart = (int)Tools::getValue('id_cart');
$id_shop = (int)Tools::getValue('id_shop');
$this->context->cookie->id_cart = $id_cart;
$link_order = $this->context->link->getPageLink('order');
$testShop = Context::getContext()->shop;
//HERE I OBTAIN THE storeOLD instead storeNEW so I am redirecting again to storeOLD
$testShop = json_decode(json_encode($testShop), true);
$newUrlToRedirect = "http://".$testShop['domain'].$testShop['physical_uri'].$testShop['virtual_uri'].'quick-order';
//print $newUrlToRedirect;
$cart = new Cart(33);
$cart->delete();
Tools::redirect($newUrlToRedirect);
}
public function initContent() {
parent::initContent();
}
}
I had put some clarifications in the code as comments. The question is, how can I change the active store??
I have found my own answer. Instead of getting the context in $testShop = Context::getContext()->shop;
Change that line for:
$testShop = new Shop($id_shop);
$testShop->getContext();
Everything fine. Thanks!
I have a file in my yii first project. my project has a new theme with this path
first_proj\themes\project\views\layouts\main.php
and i want to call a function in it like below
<?php
if($is_project_manager){
?>
<div class="each-pop-el" style="cursor:pointer" ng-click="showAllMemberTask()">show tasks</div>
<?php } ?>
and have function in
first_proj\protected\controllers\project.php
this is
public function actionIsProjectmanager(){
$project_manager = false;
$crt = new CDbCriteria;
$crt->condition = 'user_id=:uid and role=1';
$crt->params = array('uid'=>Yii::app()->user->id);
$project_manager= projectMember::model()->findAll($crt);
// $model_result = MyModel::model()->test();
$this->render('the url to theme and main.php file', array('is_project_manager' => $project_manager));
}
how can i reach to that main.php file ? what i must write instead of
the url to theme and main.php file in my function ?
You set the controllers layout to the file. So it would look like this:
$this->layout = 'main';
Layouts must be rendered with a view file as well though.
$this->render('index', array('is_project_manager' => $project_manager));
Then place an index.php file in your views/project folder with the actions content.
This assumes you've setup your config to have the theme as project
First thing you need to know is: No need to pass layout file to the view. When you use render() function, yii automatically add layout to your view. Then, For specifying the layout, you need to use $this->layout = '//layouts/main in your action.
use this in your view
<?php
if($this->isProjectmanager){
?>
<div class="each-pop-el" style="cursor:pointer" ng-click="showAllMemberTask()">show tasks</div>
<?php } ?>
and create a helper function (not an action!) in your controller
public function IsProjectmanager(){
if ($someConditon) {
return true;
}
else {
return false;
}
}