> For the complete documentation index, see [llms.txt](https://docs.cmsfullform.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cmsfullform.com/cms/helpers/frontend-helper.md). Agents can also search and read this documentation through its [MCP server](https://docs.cmsfullform.com/~gitbook/mcp).

# 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()`**

* **Purpose**: Returns the base URL of the application, including the language.
* **Parameters**:
  * `$path` (string): Additional path to append to `base_url`.
* **Usage**:

  <pre class="language-php"><code class="lang-php"><strong>echo base_url();
  </strong><strong>// Output: https://your_domain//
  </strong><strong>
  </strong><strong>echo base_url('dashboard'); 
  </strong><strong>// Output: https://your_domain/dashboard
  </strong></code></pre>

#### **`public_url()`**

* **Purpose**: Returns the URL of the `public` directory in the application.
* **Parameters**:
  * `$path` (string): File or folder path inside `public`.
* **Usage**:

```php
echo public_url(); 
// Output: https://your_domain/

echo public_url('dashboard'); 
// Output: https://your_domain/dashboard
```

#### **`history_post_url()`**

* **Purpose**: Returns the URL for the user's viewed post history.
* **Parameters**:
  * `$posttype` (string): Type of post.
* **Usage**:

```php
echo history_post_url('novel'); 
// Output: /en/user/history/novel
```

***

#### **`api_rating()`**

* **Purpose**: Returns the API URL for rating a post.
* **Parameters**:
  * `$posttype` (string): Type of post.
  * `$id` (int): Post ID.
* **Usage**:

```php
echo api_rating('movie', 123); 
// Output: https://your_domain/en/api/v1/posts/action/rating/movie/123
```

#### **`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**:

```php
echo api_count_view('novel', 456); 
// Output: /vi/api/v1/posts/action/views/novel/456
```

#### **`api_like_post()`**

* **Purpose**: Returns the API URL to like a post.
* **Parameters**:
  * `$posttype` (string): Type of post.
  * `$id` (int): Post ID.
* **Usage**:

```php
echo api_like_post('movie', 789); 
// Output: /vi/api/v1/posts/action/like/movie/789
```

***

## `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**:

```php
echo update_lang_url('en'); 
// Output: /en/
```

***

## `auth_url()`

* **Purpose**: Returns the URL for user authentication.
* Parameters:
  * `$path` (string, optional): Additional path.
  * `$lang` (string, optional, default=`LANG`): Language identifier.
* **Usage**:

```php
echo auth_url('login'); 
// Output: https://your_domain/en/user/login/
```

***

## `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**:

```php
echo cat_url('action', 'movie'); 
// Output: /en/movie/cat/action/
```

***

## `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**:

```php
echo page_url('about-us', 'page'); 
// Output: /en/page/about-us/
```

***

## **`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**:

```php
echo single_url('how-to-code', 'blog'); 
// Output: /vi/blog/how-to-code/
```

***

## `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**:

```php
echo chapter_url('novel', 'one-piece', 5); 
// Output: /en/novel/one-piece/tap-5/
```

***

## `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**:

```php
echo table_posttype('blog'); 
// Output: fast_posts_blog

echo table_posttype_relationship('blog'); 
// Output: fast_posts_blog_rel
```

***

## `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**:

```php
echo iframe_url('movie', 'avatar'); 
// Output: /en/avatar/movie/play/
```

***

## `user_url()`

* **Purpose**: Returns the URL for a user's page.
* Parameters:
  * `$slug` (string): The unique identifier or username of the user
* **Usage**:

```php
echo user_url('profile', 'john-doe'); 
// Output: /en/manage/profile/john-doe/
```

***

## `convert_to_string_number()`

* **Purpose**: Converts numbers to a compact format (`K`, `M`, `B`).
* **Parameters:**
  * `$num` (int|float): The number to be formatted.
* **Usage**:

```php
echo convert_to_string_number(1500); 
// Output: 1.50K
```

***

## `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**:

```php
echo api_upload_url(); 
// Output: https://your_domian/api/files/upload
```

{% hint style="success" %}
**Conclusion**

* These functions help generate dynamic URLs for the frontend.
* Most URLs are processed based on language (`LANG`).
* Input parameters are sanitized before use.
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.cmsfullform.com/cms/helpers/frontend-helper.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
