Frontend helper
The frontend_helper.php file in the CMS provides helper functions for handling URLs and formatting data for the frontend. These functions facilitate the creation of dynamic URLs, number conversions, debugging data, and API URL construction.
base_url()
base_url()Purpose: Returns the base URL of the application, including the language.
Parameters:
$path(string): Additional path to append tobase_url.
Usage:
echo base_url(); // Output: https://your_domain// echo base_url('dashboard'); // Output: https://your_domain/dashboard
public_url()
public_url()Purpose: Returns the URL of the
publicdirectory in the application.Parameters:
$path(string): File or folder path insidepublic.
Usage:
echo public_url();
// Output: https://your_domain/
echo public_url('dashboard');
// Output: https://your_domain/dashboardhistory_post_url()
history_post_url()Purpose: Returns the URL for the user's viewed post history.
Parameters:
$posttype(string): Type of post.
Usage:
echo history_post_url('novel');
// Output: /en/user/history/novelapi_rating()
api_rating()Purpose: Returns the API URL for rating a post.
Parameters:
$posttype(string): Type of post.$id(int): Post ID.
Usage:
echo api_rating('movie', 123);
// Output: https://your_domain/en/api/v1/posts/action/rating/movie/123api_count_view()
api_count_view()Purpose: Returns the API URL to increment the view count of a post.
Parameters:
$posttype(string): Type of post.$id(int): Post ID.
Usage:
echo api_count_view('novel', 456);
// Output: /vi/api/v1/posts/action/views/novel/456api_like_post()
api_like_post()Purpose: Returns the API URL to like a post.
Parameters:
$posttype(string): Type of post.$id(int): Post ID.
Usage:
echo api_like_post('movie', 789);
// Output: /vi/api/v1/posts/action/like/movie/789update_lang_url()
update_lang_url()Purpose: Updates the language in the current URL. Used for use in language switching links.
Parameters:
$new_lang(string): New language (e.g.,en,vi).$new_slug(string): New slug.
Usage:
echo update_lang_url('en');
// Output: /en/auth_url()
auth_url()Purpose: Returns the URL for user authentication.
Parameters:
$path(string, optional): Additional path.$lang(string, optional, default=LANG): Language identifier.
Usage:
echo auth_url('login');
// Output: https://your_domain/en/user/login/cat_url()
cat_url()Purpose: Returns the URL for a post category.
Parameters:
$slug(string): The slug (short URL) of the post category.$posttype(string): The type of post (post type).
Usage:
echo cat_url('action', 'movie');
// Output: /en/movie/cat/action/page_url()
page_url()Purpose: Returns the URL for a specific page.
Parameters:
$slug(string): The slug (short URL) of the post category.$posttype(string): The type of post (post type).
Usage:
echo page_url('about-us', 'page');
// Output: /en/page/about-us/single_url()
single_url()Purpose: Returns the URL for a single post.
Parameters:
$slug(string): The slug (short URL) of the post category.$posttype(string): The type of post (post type).
Usage:
echo single_url('how-to-code', 'blog');
// Output: /vi/blog/how-to-code/chapter_url()
chapter_url()Purpose: Returns the URL for a post's chapter.
Parameters:
$slug(string): The slug (short URL) of the post category.$chap(string|int): The chapter or episode number.$posttype(string): The type of post (post type).
Usage:
echo chapter_url('novel', 'one-piece', 5);
// Output: /en/novel/one-piece/tap-5/table_posttype() & table_posttype_relationship()
table_posttype() & table_posttype_relationship()Purpose: Returns the database table name for the given
posttype.Parameters:
$posttype(string) : The type of post (e.g.,"blog","movie","product").Usage:
echo table_posttype('blog');
// Output: fast_posts_blog
echo table_posttype_relationship('blog');
// Output: fast_posts_blog_reliframe_url()
iframe_url()Purpose: Returns the URL for viewing content via an iframe.
Parameters:
$slug(string): The slug (short URL) of the post category.$posttype(string): The type of post (post type).
Usage:
echo iframe_url('movie', 'avatar');
// Output: /en/avatar/movie/play/user_url()
user_url()Purpose: Returns the URL for a user's page.
Parameters:
$slug(string): The unique identifier or username of the user
Usage:
echo user_url('profile', 'john-doe');
// Output: /en/manage/profile/john-doe/convert_to_string_number()
convert_to_string_number()Purpose: Converts numbers to a compact format (
K,M,B).Parameters:
$num(int|float): The number to be formatted.
Usage:
echo convert_to_string_number(1500);
// Output: 1.50Kapi_upload_url()
api_upload_url()Purpose: Returns the API URL for file uploads.
Parameters:
$act(string): The action to be performed (e.g.,"image_upload","video_upload").$params(array): Additional parameters to be added to the API request.
Usage:
echo api_upload_url();
// Output: https://your_domian/api/files/uploadConclusion
These functions help generate dynamic URLs for the frontend.
Most URLs are processed based on language (
LANG).Input parameters are sanitized before use.
Last updated
Was this helpful?