Parent Theme not follow in the controller template prestashop - prestashop

Hi I have created a controller in which I am setting the template. It is a front controller. The problem I am getting is that the parent theme is not followed in the controller rather I just get another page uniquely all by itself and by the looks of it it is like that the template is not attached to the module. Currently the controller is just basic. I am beginner. I have attached the controller code. The code of my tpl file is also added. I have attached an image to show the problem.I haven't done any changes elsewhere just calling the controller from the module.php file by the link. Thank you in advance.
//controller code
class ExperimentFirstPageModuleFrontController extends ModuleFrontController
{
public $ssl = true;
public function __construct()
{
$this->bootstrap = true;
parent::__construct();
$this->context = Context::getContext();
}
public function initContent()
{
parent::initContent();
$this->context->smarty->assign(array());
$this->setTemplate('module:experiment/views/templates/front/list.tpl');
}
public function setMedia()
{
parent::setMedia();
$this->addjQuery();
}
}
//tpl file
<h>hello</h>

Related

.Net Maui Shell Navigation - Is it possible to pass a Query Parameter and Auto Populate a Page?

I need to auto populate a Page by passing a Shell Navigation Parameter to a ViewModel/Method and call a Service to return a single record from a Web Service. Essentially a drill-through page. My issue is that I need to call the data retrieveal command, "GetFieldPerformanceAsync" (note [ICommand] converts this to "GetFieldPerformanceCommand") from the "To" Page's code-behind from within OnNavigatedTo. This is required since the Shell Navigation Parameter is not set in the ViewModel until the Page is loaded. I'm currently unable to make the Command call from OnNavigatedTo and need advice on how to accomplish this.
Thanks!
Code behind the Page:
public partial class FieldPerformancePage : ContentPage
{
public FieldPerformancePage(FieldPerformanceViewModel viewModel)
{
InitializeComponent();
BindingContext = viewModel;
//works with parameter hard-coded in ViewModel
//viewModel.GetFieldPerformanceCommand.Execute(null);
}
FieldPerformanceViewModel viewModel;
protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
base.OnNavigatedTo(args);
//this does not work
viewModel.GetFieldPerformanceCommand.Execute(null);
}
}
ViewModel
namespace TrackMate.ViewModels;
[QueryProperty(nameof(FieldAssignedWbs), nameof(FieldAssignedWbs))]
public partial class FieldPerformanceViewModel : BaseViewModel
{
[ObservableProperty]
FieldAssignedWbs fieldAssignedWbs;
[ObservableProperty]
FieldPerformance fieldPerformance;
FieldPerformanceService fieldPerformanceService;
public FieldPerformanceViewModel(FieldPerformanceService fieldStatusService)
{
Title = "Status";
this.fieldPerformanceService = fieldStatusService;
}
[ICommand]
async Task GetFieldPerformanceAsync()
{
if (IsBusy)
return;
try
{
IsBusy = true;
int wbsId = fieldAssignedWbs.WbsId;
var fieldPerformanceList = await fieldPerformanceService.GetFieldPerformanceList(wbsId);
if (fieldPerformanceList.Count != 0)
FieldPerformance = fieldPerformanceList.First();
}
catch (Exception ex)
{
Debug.WriteLine(ex);
await Shell.Current.DisplayAlert("Error!",
$"Undable to return records: {ex.Message}", "OK");
}
finally
{
IsBusy = false;
}
}
}
I believe I figured it out...
By adding ViewModel Binding within the OnNavigatedTo method in the "DetailsPage" Code Behind, a Command Call can be made to the Page's ViewModel to execute data retrieval method after the Shell Navigation Parameter (object in this scenario) passed from the "Main" Page has been set. Note a null is passed since the Query Parameter is sourced from the ViewModel. If you are new to .Net Maui, as I am, I recommend James Montemagno's video on .Net Maui Shell Navigation.
namespace TrackMate.Views;
public partial class FieldPerformancePage : ContentPage
{
public FieldPerformancePage(FieldPerformanceViewModel viewModel)
{
InitializeComponent();
BindingContext = viewModel;
}
protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
FieldPerformanceViewModel viewModel = (FieldPerformanceViewModel)BindingContext;
viewModel.GetFieldPerformanceCommand.Execute(null);
base.OnNavigatedTo(args);
}
}
For me it only worked when the BindingContext assignment is before the component initialization and the method call after the base call in OnNavigatedTo
public partial class OccurrencePage : ContentPage
{
public OccurrencePage(OccurrenceViewModel model)
{
BindingContext = model;
InitializeComponent();
}
protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
base.OnNavigatedTo(args);
OccurrenceViewModel viewModel = (OccurrenceViewModel)BindingContext;
viewModel.GetFieldsCommand.Execute(null);
}
}
While overriding OnNavigatedTo works fine, there is one more simple technique to run something once your query param is set, given you do not need to run anything asynchronous inside the method: implementing partial method OnFieldAssignedWbsChanged, auto-generated for your convenience by mvvm toolkit
partial void OnFieldAssignedWbsChanged(FieldAssignedWbs value)
{
// run synchronous post query param set actions here
}
Less amount of code and less code-behind and viewModel dependencies, but works fine for non-async operations only.

Laravel controller based api routing

My normal web app runs w/o any issue. Then I wanted to experiment with APIs. I enabled Passport since I need api authorization (but at this moment, I rather want to get this thing working and I have no idea whether it is a problem with Passport) and I wanted to get simple json output of specific Product. So far, I was not able to get it working. I'll describe contents of each file and if someone can direct me to find the issue in my code, that would be great.
Resources\Product.php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class Product extends JsonResource
{
public function toArray($request)
{
return parent::toArray($request);
}
}
Providers\AuthServiceProviders.php
public function boot()
{
$this->registerPolicies();
Passport::routes();
}
User.php
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
...
}
ProductController.php
class ProductController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function apiShow(Product $product)
{
return new ProductResource($product);
}
...
}
routes/api.php
Route::get('/products/{product}', 'ProductController#apiShow');
Now if I go to http://localhost/public/products/1, it displays the page as expected. But if I type in http://localhost/public/api/products/1, it will always go to home page which is set to localhost/public in HomeController.
If I modify routes/api.php as:
Route::get('/products/{id}', function($id) {
return Product::find($id);
});
I get the correct json output in the browser.

prestashop 1.6 custom page don't work?

I have create a Test controller using the code in : Create Custom page in Prestashop 1.5.3.1
class MyPageController extends FrontController
{
public $php_self = 'mypage';
public function init() {
parent::init();
}
public function initContent() {
parent::initContent();
die('test!');
}
}
I put it in the /controllers/front/MyPageController.php and it does not work. i get a clean html page.
What am I missing ?
link to custom page : http://www.funtoy.co.il/index.php?controller=MyPage
Edit 1 :
fix the semicolon at $php_self = 'mypage';
Thanks.
yaniv abo
Remove cache/class_index.php to clear the cache.

Prestashop ModuleAdminController use simple template

Trying to figure out why something like the below cant work. There is a tab in the preferences admin section that points to this controller but when going to it it always output a blank page. I have tried several things but the below is basically what I need. There is no MODEL... I simply need this to get the uploaded file for postProcessing...
The controller file...
class AdminAstroImporterController extends ModuleAdminController {
public function initContent() {
parent::initContent();
return $this->display(__FILE__, 'import.tpl');
}
public function postProcess() {
//do something here
}
}
Looks like you can overide the actual content output by doing as shown in the initContent() function shown below. The 'content' in the smarty assign can be any html you generate yourself.
class AstroImporterAdminController extends AdminController {
public function __construct() {
parent::__construct();
//load current settings
$this->data = unserialize(Configuration::get('ASTRO_IMPORTER'));
}
public function initContent() {
parent::initContent();
$this->show_toolbar = false;
$this->context->smarty->assign(array(
'content' => $this->renderSettings().$this->renderForm().$this->displayFields(),
));
}
I found that this works:
public function renderList()
{
global $currentIndex, $cookie;
$smarty = $this->context->smarty;
$smarty->assign('currentIndex', $currentIndex);
return $this->context->smarty->fetch($this->getTemplatePath().'/main.tpl');
}
Although its dirty as hell, it seems cleaner than Amb3rL4nn answer.
In v1.4 it was very easy to create a tab (and easy to find documentation) I wonder why they changed it and didn't supply an docs.

Problem in Creating Simple Form in Zend

I am new on Zend Framwork(MVC). I want to crate simple a Form with some HTML control.
I have create one controller IndexController, code are as follows:
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
/*$this->view->var = 'User Login Page';*/
$form = new Form_Login();
$this->view->form=$form;
}
}
And my Form's code in application/forms/Login.php:
<?php
require_once('Zend/Form.php');
class Form_Login extends Zend_Form
{
public function init()
{
parent::__construct($options);
// the code bellow will create element
$username = $this->CreateElement('text','username');
$username->setLabel("Username:");
// and
$submit= $this->CreateElement("submit","submit");
$submit->setLabel("Submit");
// now add elements to the form as
$this->addElements(array(
$username,
$submit
));
}
}
?>
When i run this project then its show an error like this:
**Fatal error: Class 'Form_Login' not found in C:\xampp\htdocs\LoginForm\application\controllers\IndexController.php on line 16**
Please help me...
Thanks
Pankaj
Everything looks good, make sure your Login.php file has this as the first lines:
<?php
class Form_Login extends Zend_Form
{
public function init()
If that doesn't help, you might want to check your index.php/Bootstrap.php files and server configuration to make sure all paths are correct.