Include files inside modules folder in Prestashop - php

I have created a subfolder inside my store in Prestashop inside the /classes/ subdirectory with the name service (e.g /classes/service/).
I'm trying to include the php file of a module that I have created myself to access to its methods with the following line of code inside a class that I have created inside /classes/service/ :
include(dirname(__FILE__).'/../../modules/mymodulename/mymodulename.php')';
class A {
.
.
.
public function callmodule(){
$obj = new MyModuleName();
$obj->someMethod();
}
}
I use it in the include the /../../ to go two directories up, one to get out to the service folder and another one to get out to the root folder of the store, but the problem is that the above line is not returning anything when I call it, only gave me a blank page without errors or warning and if I delete it's works fine, but I need to access to this file.
There is a better way to access to the file without errors ?
PD : When I mean call the class A it's because I put a rule inside my .htaccess to redirect a specific call to some class like a dispatcher where the A class its called.

Related

how to duplicate a page in codeigniter?

I'm new to codeigniter environment. I have this existing system and I am trying to duplicate one of the admin pages which I thought would work if i just copy, rename and paste.
Example:
(original files and working)
application\controllers\admin\calculator.php
application\views\admin\calculator.php
it can be access by domain.org/admin/calculator
(duplicated)
application\controllers\admin\calculatorduplicate.php
application\views\admin\calculatorsduplicate.php
tried accessing by domain.org/admin/calculatorduplicate
but showing 404
I also added the navigation link inside this file.
application\views\admin\header.php
What am i missing? I didn't want to change anything inside the file yet, just want to duplicate the page. Please help.
Firstly, first try to understand how CodeIgniter binds its URLs.
In URL:
http://codeignitersite.com/controller/method/parameter_one/parameter_two/[parameters].....
Controller is the Controller class which must have the same name as of its Filename and also as in URL.
Method is the Controller method to be accessed.
In above case, the class name also needs to be changed to:
class Calculatorduplicate {
To avoid any 404 error.

Laravel #extends() pointer system

Laravel 5.7.
If I navigate to a page that does not exist, I get 404 error page handling.
That view is located in vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Views/404.blade.php
However this file extends:
#extends('errors::illustrated-layout')
This is located in the same folder, and is named illustrated-layout.blade.php
So I guess that the errors:: part points to the specific folder., e.g. vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Views/
Question: Is this type of pointer something that could be created manually, so a person wouldn't have to write the entire path to a specific folder, when extending a view? Would make things much more clean.
You can add a view namespace and achieve the same result.
For example, you can add the following in AppServiceProvider#boot:
$this->app['view']->addNamespace('admin', base_path() . '/resources/views/admin');
and let's suppose you have a blade file in resources/views/admin/layouts/master.blade.php
you can access it with admin::layouts.master

Create for each hook function a file in WHMCS modules

In WHMCS can i use a folder for hooks inside of hooks.php in modules/addons/ like in includes/hooks?. I test it but it don't work. and i tried to find solution by creating a folder named hooks and inside this folder i create files that contain functions: Exemple :
In modules/addons/myModule/hooks/function1.php :
function function1($vars){
// .....
}
In modules/addons/myModule/hooks.php :
if (!defined("WHMCS"))
die("This file cannot be accessed directly");
foreach (glob("hooks/*.php") as $filename)
{
include($filename);
}
add_hook("ClientAreaHeadOutput", 1, "function1.php");
My solution don't work. There is any best solution for that? Thanks.
To get an addon detected put your addon folder inside modules/addons/ e.g modules/addons/mymodule and then inside your module folder have a php file with the same name modules/addons/mymodule/mymodule.php. Your functions go into this file.
You will then go to Setup > Addon Modules interface and activate it.

How to connect codeigniter controller method from Jquery code in a view file (placed in folder)

I am using the autocomplete plugin in Jquery as follows:
$(function(){
$("#username").autocomplete({
source: "http://localhost/websitename/index.php/admin/suggest_names" // path to the method in controller
});
});
The code for the text box is
<input type="text" name="username" id="username">
The suggest_names method in controller in turn calls a method in the model
I have tried providing the path to the method in controller by using
source: "admin/suggest_names"
in the above code.
However this is not working when the file is placed in a sub folder within the views folder application/views/admin. This works when the file is placed directly within the views folder.
I have tried using site_url but this does not work as well. (the form helper function is loaded in the administrator)
Can you suggest where I am making a mistake and suggest the syntax for the code to be used.
Stick to the following structure:
VIEW:
Your jquery function must be in a view file (it can be in the
Application/Views
directory or in a subdirectory of view). A view file is displayed in the browser and so the jquery code can run on client side. The controller is called from here. Your first code block example seems to be correct. You can also use: source: "/index.php/admin/suggest_names".
CONTROLLER:
A Controller (in your case called admin) is simply a class file that is named in a way that can be associated with a URI. They are placed in the
Application/Controllers
directory or a subdirectory of it. In your case you are calling the function suggest_names(), where you prepare the $data you want to output in the view file and call the database functions from a model (that last one is optional, you could treat the database functions from the controller as well).
MODELS:
Models are PHP classes that are designed to work with information in your database. They are placed in the
Application/Models
directory or subdirectory of it.

cakephp controller not found error on production server

I have a cakephp project under folder FC such that on ubuntu, it's path is /var/www/FC/app/...
Upon uploading to ec2 and making all configuration changes, the base path, ie. index.php is correctly opening but any other link on index.php is giving an error:
Error: FCController could not be found.
Error: Create the class FCController below in file: app/Controller/FCController.php
class FCController extends AppController {
}
Upon creating this file, it asks to put method locations into the class FCcontroller, and on putting an empty method in the class, the display goes blue like an empty page.
Since I haven't written this code I have no clue where the data which should be here is written...what should I Do?
You need to alter these three lines in your app\webroot\index.php:
// The full path to the directory which holds "app", WITHOUT a trailing DS.
define('ROOT', '/var/www/FC');
// The actual directory name for the "app".
define('APP_DIR', 'app');
// The absolute path to the "cake" directory, WITHOUT a trailing DS.
define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'lib');
to point to their respective locations.
(the last of the three is commented by default, so you'll need to uncomment it.
i sorted the issue out. It was because in my code, the previous user had made a controller file Locationscontroller.php and specified urls like this:
<form id ="0" action="/FC/locations/confirm_final">
This was for localhost in my local machine where the base folder was htdocs I had to type localhost/FC/ to access index.php.
So naturally Since on EC2 I had made FC itself my base folder, it was trying to access another FC inside it which didn't exist. The /XXX/locations/ means it searches for "XXX" controller and then locations inside it. Since my controller was Locations, it kept giving an error.
As soon as I changed it to this:
<form id ="0" action="/locations/confirm_final">
It pointed to the right controller which was locations.
It was all because I didn't check which controller was called by which View!
I'm an idiot, that'll be all :D

Categories