Post by mauphung » Sun Mar 10, 2024 3:03 am

I want to create a simple Hello extension to display Hello in OC4.0.2.3, but it returns a message The page you requested cannot be found!
Please tell me why or is there any similar example?
http://localhost/oc4023/index.php?route ... mext/hello
***
My extension/mext folder has a controller folder and view folder as follows:
My Controller: catalog/controller/hello.php
<?php
namespace Opencart\Catalog\Controller\Extension\Mext;
/**
* Class Hello
*
* @package
*/
class Hello extends \Opencart\System\Engine\Controller {
/**
* @return string
*/
public function index(): string {
$data['text_title'] = "Title";
$data['text_hello'] = "Hello";

return $this->load->view('extension/mext/hello', $data);
}
}
My View: category/view/hello.twig
<div class="card">
<div class="card-header">{{ text_title }}</div>
<p style="text-align: center;">{{ text_hello }}</p>
</div>

Content of install.json file:
{
"name": "hello",
"version": "1.0.0",
"author": "MPN",
"link": "http://localhost"
}

Newbie

Posts

Joined
Mon Oct 14, 2013 12:06 am

Post by straightlight » Sun Mar 10, 2024 3:21 am

The extension route cannot be used from the URL on the catalog-end side.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by andersonre » Tue Mar 19, 2024 9:21 am

Check Controller Namespace: In the console file, the namespace must match the folder structure. Change namespace Opencart\Catalog\Controller\Extension\Mext; to the Controller\Extension\Mext; namespace.

Controller Class Name: Make sure your console class name matches the file name. In this case it must be the ControllerExtensionMextHello class.

View Folder Structure: The folder view structure must match your console namespace. In your case, the view file should be located in catalog/view/extension/mext/hello.twig.

Access URL: Make sure you are accessing the correct URL to view your Hello extension. It should be something like https://ncedcloudam.com http://localhost/oc4023/index.php?route ... mext/hello.

Check Twig File: Make sure your twig file has the correct structure and content

Hope this will help you

Newbie

Posts

Joined
Tue Mar 19, 2024 9:08 am
Who is online

Users browsing this forum: No registered users and 7 guests