PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, June 30, 2022

[FIXED] How to get Prestashop admin dir & admin url?

 June 30, 2022     prestashop     No comments   

Issue

i am trying to get admin url and admin dir from a module.

Can you give an example finding admin url and admin dir from a module php page?

<?php
define('PS_ADMIN_DIR', dirname(__file__) . '/../../testadmin');  
echo PS_ADMIN_DIR;

this code gives me

/home/myaccount/public_html/modules/suppliers/../../testadmin

i was expecting to get

/home/myaccount/public_html/testadmin

Any ideas?


Solution

You can get it by using " _PS_ROOT_DIR_ " and append your admin dir name with it like below

 _PS_ROOT_DIR_."/testadmin" 

This will give you full path to the admin directory. The _PS_ROOT_DIR_ is used to get the PS complete path to directory where it is installed.

You can't get the admin url directly, as PS system dont know the admin directory, because we can change the admin directory name at any time to any name for security reasons. So to construct an admin url knowing your admin directory name "testadmin" and the controller name "AdminTest", you can create a url as below

$link = new Link(); 
_PS_BASE_URL_.__PS_BASE_URI__."testadmin/".$link->getAdminLink('AdminTest', true);

This will give you complete link including full domain and sub directory (if installed in sub directory).

the getAdminLink gets two argument , controller name and second is Boolean true / false. By default the second is set to true, so need to pass it. It is used to create the token for the controller.

I hope this will help you.

Note : The above code is just for idea, it may or may not need some changes.



Answered By - Altaf Hussain
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing